CheckBox UITableViewCell
一个简单的自定义CheckBox UITableViewCell
效果:
UITableViewCheckBoxCell.h
1 // 2 // UITableViewCheckBoxCell.h 3 // TableViewStudy 4 // 5 // Created by Shawn on 12/16/12. 6 // Copyright (c) 2012. All rights reserved. 7 // 8 9 #import <UIKit/UIKit.h> 10 11 @interface UITableViewCheckBoxCell : UITableViewCell 12 13 @property (nonatomic) BOOL isChecked; 14 15 - (id)initWithReuseIdentifier:(NSString *)reuseIdentifier; 16 17 @end
UITableViewCheckBoxCell.m
1 // 2 // UITableViewCheckBoxCell.m 3 // TableViewStudy 4 // 5 // Created by Shawn on 12/16/12. 6 // Copyright (c) 2012. All rights reserved. 7 // 8 9 #import "UITableViewCheckBoxCell.h" 10 @interface UITableViewCheckBoxCell() 11 12 @property (nonatomic,retain) UIButton *btnCheck; 13 @end 14 15 @implementation UITableViewCheckBoxCell 16 @synthesize btnCheck = _btnCheck; 17 @synthesize isChecked = _isChecked; 18 19 - (void)dealloc 20 { 21 [_btnCheck release]; 22 [super dealloc]; 23 } 24 25 - (id)initWithReuseIdentifier:(NSString *)reuseIdentifier 26 { 27 self = [self initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier]; 28 29 return self; 30 } 31 32 - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 33 { 34 self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 35 if (self) { 36 _isChecked = FALSE; 37 CGRect rect = self.contentView.bounds; 38 rect.origin.x = 10; 39 rect.origin.y = 5; 40 rect.size.width -= 45; 41 [self.textLabel setFrame:rect]; 42 43 rect = self.contentView.bounds; 44 rect.origin.x = rect.size.width - 35; 45 rect.origin.y = (rect.size.height - 25) / 2; 46 rect.size.width = 25; 47 rect.size.height = 25; 48 _btnCheck = [[UIButton alloc] initWithFrame:rect]; 49 [_btnCheck setBackgroundColor:[UIColor lightGrayColor]]; 50 [_btnCheck setTitle:@"" forState:UIControlStateNormal]; 51 [_btnCheck setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; 52 [_btnCheck.titleLabel setFont:[UIFont systemFontOfSize:12]]; 53 54 [_btnCheck addTarget:self action:@selector(btnCheckClicked) forControlEvents:UIControlEventTouchUpInside]; 55 self.selectionStyle = UITableViewCellSelectionStyleNone; 56 [self.contentView addSubview:_btnCheck]; 57 } 58 return self; 59 } 60 61 - (void)btnCheckClicked 62 { 63 if (!self.isChecked) { 64 [_btnCheck setTitle:@"✔" forState:UIControlStateNormal]; 65 [_btnCheck setBackgroundColor:[UIColor redColor]]; 66 _btnCheck.selected = TRUE; 67 self.isChecked = TRUE; 68 } 69 else 70 { 71 [_btnCheck setTitle:@"" forState:UIControlStateNormal]; 72 [_btnCheck setBackgroundColor:[UIColor lightGrayColor]]; 73 _btnCheck.selected = FALSE; 74 self.isChecked = FALSE; 75 } 76 } 77 - (void)setSelected:(BOOL)selected animated:(BOOL)animated 78 { 79 [super setSelected:selected animated:animated]; 80 81 // Configure the view for the selected state 82 } 83 84 @end
转载于:https://www.cnblogs.com/ishawn/archive/2012/12/16/TableView.html
CheckBox UITableViewCell相关推荐
- Ios中checkBox
//使用tableview来进行布局checkBox.便于全选,全不选//radiobutton 适合用RadioButton #import <UIKit/UIKit.h>@interf ...
- uitableviewcell选中打勾
单元格选中后,打勾.再选其他,之前的勾取消,新的打勾. 代码如下(不加代码高亮了吧): - (NSIndexPath *)tableView:(UITableView *)tableView will ...
- 点击文字可以选中相应的checkbox
点击文字可以选中相应的checkbox (2008-11-22 14:16:40) 转载▼ 标签: 杂谈 分类: javascript 转载: 这是一个例子: <html> <hea ...
- Android CheckBox 点击的时候没有效果
写了一个CheckBox 点击的时候没有效果 感觉莫名其妙的,最后在xml 中设置了 android:clickable="true" 点击有效果了, 见鬼了.
- Android CheckBox 修改选择框
效果图 是否被选中打印效果图图 CheckBox 是多选框 ,选中之后可以再次点击取消操作. 在使用的时候注意padding 是相对于字体来的不是相对选择框 下面第一个位置调整了 使用了paddin ...
- ASP.NET MVC3 在WebGrid中用CheckBox选中行
分三步走 1.保证你的webgrid包含在form中 @using (Html.BeginForm("Assign","Home")) { } 2.在webgr ...
- ASP.NET DEMO 14: 如何在 GridView/DataGrid 模板列中使用自动回发的 CheckBox/DropDownList
有时候希望在 GridView 模板中使用自动回发的 CheckBox (autopostback=true) ,但是 CheckBox 没有 CommandName 属性,因此也就无法在 GridV ...
- 用js 判断datagrid 中的 checkbox 是否被选中
private void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 ...
- CSS3重新定义input中呆若木鸡的默认复选框CheckBox和单选框Radio样式
<!DOCTYPE html> <html> <head><meta charset="UTF-8"><style>/* ...
最新文章
- 重构-改善既有代码的设计:对象之间移动特性的八种方法(五)
- 【转】使用ant来调用Jmeter,并定制运行时参数
- VS在win32平台与mysql链接_visual C++如何与MySQL在windows下建立连接
- 64位百度云 catia v6_福利缩水:百度网盘决定收回部分储存空间
- 技巧 | 如何批量地将整型变量转换为因子变量
- 发现个好玩的,去页面敲键盘,页面键变色
- Go基础学习记录 - 编写Web应用程 - 完善Blog Model
- 移动通信-抗衰落技术
- 《麦肯锡·卓越工作方法》
- echarts饼图:实现多层图表同步自动轮播,鼠标悬浮时停止轮播,移出鼠标后重新开始轮播效果
- OSEK直接网络管理软件开发
- 人的感性是否也属于理性的一种
- Sea.js框架构建
- gabor与gabor小波
- php gif裁剪,ci裁剪gif图片如何让gif保持是动态的。
- 一开机checkingmedia_电脑开机出现checking media怎么办?
- 数据库Oracle基本命令
- Plugin ‘org.springframework.boot:spring-boot-maven-plugin:‘ not found
- 用python把json文件转excel
- Systemd日志管理:使用Journalctl查看和处理系统日志