Ios中checkBox
//使用tableview来进行布局checkBox.便于全选,全不选
//radiobutton 适合用RadioButton #import <UIKit/UIKit.h> @interface CheckView : UIView<UITableViewDataSource,UITableViewDelegate>
- (id)initWithFrame:(CGRect)frame Data:(NSArray *)data;
-(void)CkNotAllSelect;
-(void)CkAllSelect;
@end #import "CheckView.h"
#import "CommonButton.h"
#define Kcount 3 @interface CheckView (){
UITableView *_tableview;
} @property(nonatomic,retain)NSArray *MyData;
@property(nonatomic,retain)NSMutableArray *chooseArrary;
@end @implementation CheckView - (id)initWithFrame:(CGRect)frame Data:(NSArray *)data
{
self = [super initWithFrame:frame];
if (self) {
self.MyData=data;
_tableview=[UITableView TableViewWithFrame:self.bounds style:UITableViewStylePlain backgroundColor:[UIColor clearColor] delegate:self separatorStyle:UITableViewCellSeparatorStyleSingleLine];
_tableview.rowHeight=;
[self addSubview:_tableview];
self.chooseArrary =[NSMutableArray arrayWithCapacity:];
for (int i=; i<data.count; i++) {
[self.chooseArrary addObject:[NSNumber numberWithBool:NO]];
} }
return self;
} -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return ; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.MyData.count%Kcount==?self.MyData.count/Kcount:self.MyData.count/Kcount+;
} -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellIndentify=@"CheckView";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIndentify];
if (cell==nil) {
cell=[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentify] autorelease];
}
int row=indexPath.row*Kcount;
int width=tableView.bounds.size.width/Kcount;
CGRect leftRect,rect=CGRectMake(, , tableView.bounds.size.width, tableView.rowHeight);
for(int i=row;i<row+Kcount;i++){
if(i>=self.MyData.count) break;
else{
CGRectDivide(rect, &leftRect, &rect, width, CGRectMinXEdge);
CommonButton *btn=[[CommonButton alloc] initWithFrame:leftRect];
[btn setTitle:self.MyData[i] forState:UIControlStateNormal];
BOOL flag=[[self.chooseArrary objectAtIndex:i] boolValue];
if (flag) {
[btn setImage:[UIImage imageNamed:@"radio_selected"] forState:UIControlStateNormal]; }
else{
[btn setImage:[UIImage imageNamed:@"radio_normal"] forState:UIControlStateNormal];
} [btn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
btn.tag=i;
[cell addSubview:btn];
}
} return cell;
} -(void)click:(CommonButton *)btn{
NSLog(@"-->%zi",btn.tag);
int tag=btn.tag;
BOOL flag=[[self.chooseArrary objectAtIndex:tag] boolValue];
if (flag) {
[self.chooseArrary replaceObjectAtIndex:tag withObject:[NSNumber numberWithBool:!flag]];
[btn setImage:[UIImage imageNamed:@"radio_normal"] forState:UIControlStateNormal]; }
else{
[self.chooseArrary replaceObjectAtIndex:tag withObject:[NSNumber numberWithBool:!flag]];
[btn setImage:[UIImage imageNamed:@"radio_selected"] forState:UIControlStateNormal];
}
} -(void)CkAllSelect{
for (int i=; i<self.MyData.count;i++) {
[self.chooseArrary replaceObjectAtIndex:i withObject:[NSNumber numberWithBool:YES]]; }
[_tableview reloadData]; } -(void)CkNotAllSelect{
for (int i=; i<self.MyData.count;i++) {
[self.chooseArrary replaceObjectAtIndex:i withObject:[NSNumber numberWithBool:NO]]; }
[_tableview reloadData];
} - (void)dealloc
{
[_chooseArrary release];
[_MyData release];
[super dealloc];
} @end
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// [self RadioButtonSelect];
// UIButton *btn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
// btn.frame=CGRectMake(0, 100, 50,50);
// [self.view addSubview:btn];
// [btn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
NSArray *arr=@[@"标题1",@"标题2",@"标题3",@"标题4"];
CheckView *checkView=[[CheckView alloc] initWithFrame:CGRectMake(, , , ) Data:arr];
_CK=checkView;
[self.view addSubview:checkView];
[checkView release]; }
Ios中checkBox的更多相关文章
- iOS中textbox文本框清除圆角
在iOS.Mac safari中,所有的textbox, select, checkbox都会被强制美化为圆角.但在特殊情况下需要清除圆角时发现iOS中使用以下传统的css无效: border-rad ...
- 解决ios中input兼容性问题
1.解决input输入框在iOS中有阴影问题 input{ -webkit-appearance: none; } 2.checkbox.raido在ios中阴影问题 单选: ...
- iOS中支付宝集成
iOS中支付宝集成 如今各种的App中都使用了三方支付的功能,现在将我在使用支付宝支付集成过程的心得分享一下,希望对大家都能有所帮助 要集成一个支付宝支付过程的环境,大致需要: 1>公司:先与支 ...
- iOS中数据库应用基础
iOS 数据库入门 一.数据库简介 1.什么是数据库? 数据库(Database) 是按照数据结构来组织,存储和管理数据的仓库 数据库可以分为2大种类 关系型数据库(主流) PC端 Oracle My ...
- 正则表达式在iOS中的运用
1.什么是正则表达式 正则表达式,又称正规表示法,是对字符串操作的一种逻辑公式.正则表达式可以检测给定的字符串是否符合我们定义的逻辑,也可以从字符串中获取我们想要的特定部分.它可以迅速地用极简单的方式 ...
- iOS 中的 HotFix 方案总结详解
相信HotFix大家应该都很熟悉了,今天主要对于最近调研的一些方案做一些总结.iOS中的HotFix方案大致可以分为四种: WaxPatch(Alibaba) Dynamic Framework(Ap ...
- iOS中使用正则
一.什么是正则表达式 正则表达式,又称正规表示法,是对字符串操作的一种逻辑公式.正则表达式可以检测给定的字符串是否符合我们定义的逻辑,也可以从字符串中获取我们想要的特定部分.它可以迅速地用极简单的方式 ...
- IOS中div contenteditable=true无法输入
在IOS中<div contenteditable="true"></div>中点击时可以弹出键盘但是无法输入.加一个样式-webkit-user-sele ...
- 谈谈iOS中的屏幕方向
众所周知,iOS中提供了[UIDevice currentDevice].orientation与[UIApplication sharedApplication].statusBarOrientat ...
随机推荐
- eclipse如何debug调试jdk源码,并显示局部变量
http://blog.csdn.net/xuefeng0707/article/details/8738869 http://blog.csdn.net/leehsiao/article/detai ...
- Laravel学习笔记之Session源码解析(中)
说明:在上篇中学习了session的启动过程,主要分为两步,一是session的实例化,即\Illuminate\Session\Store的实例化:二是从session存储介质redis中读取id ...
- w3cscholl的在线代码编辑工具2
https://www.w3cschool.cn/tryrun/runcode?lang=c
- How to duplicate the records in a MongoDB collection
// Fill out a literal array of collections you want to duplicate the records in. // Iterate over e ...
- [Algorithm] Inorder Successor in a binary search tree
For the given tree, in order traverse is: visit left side root visit right side // 6,8,10,11,12,15,1 ...
- 通过项目逐步深入了解Mybatis<二>
Mybatis 解决 jdbc 编程的问题 1. 数据库链接创建.释放频繁造成系统资源浪费从而影响系统性能,如果使用数据库链接池可解决此问题. 解决:在SqlMapConfig.xml中配置数据链接池 ...
- Reshaper cannot resolve symbol
问题 不知道出了什么问题,在代码视图发现有些关键词显示为红色,并且Reshaper提示消息为Reshaper cannot resolve symbol XXX ,但编辑不会报错. 虽然不影响使用,但 ...
- Unlicensed ARC session – terminating!
问题描述 近日,发现ArcGIS10.4中存在很多bug,而且费了好多时间去测试它,最终决定改用10.1.在降级程序时遇到许可问题. 重装ArcGIS10.1后,打开工程,所有引用都自动映射,没报任何 ...
- Percona-XtraBackup系列二:备份恢复
#在备份较大数据量的时候推荐xtrabackup,这个工具比mysqldump要快很多. 一.Xtrabackup介绍 1,Xtrabackup是什么 Xtrabackup是一个对InnoDB做数据备 ...
- Hibernate学习笔记四:事务管理
转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6768298.html 一:需要事务的Session操作 Session操作中,查询类操作是不需要事务就能生效 ...