//使用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的更多相关文章

  1. iOS中textbox文本框清除圆角

    在iOS.Mac safari中,所有的textbox, select, checkbox都会被强制美化为圆角.但在特殊情况下需要清除圆角时发现iOS中使用以下传统的css无效: border-rad ...

  2. 解决ios中input兼容性问题

    1.解决input输入框在iOS中有阴影问题 input{ -webkit-appearance: none; } 2.checkbox.raido在ios中阴影问题 单选:              ...

  3. iOS中支付宝集成

    iOS中支付宝集成 如今各种的App中都使用了三方支付的功能,现在将我在使用支付宝支付集成过程的心得分享一下,希望对大家都能有所帮助 要集成一个支付宝支付过程的环境,大致需要: 1>公司:先与支 ...

  4. iOS中数据库应用基础

    iOS 数据库入门 一.数据库简介 1.什么是数据库? 数据库(Database) 是按照数据结构来组织,存储和管理数据的仓库 数据库可以分为2大种类 关系型数据库(主流) PC端 Oracle My ...

  5. 正则表达式在iOS中的运用

    1.什么是正则表达式 正则表达式,又称正规表示法,是对字符串操作的一种逻辑公式.正则表达式可以检测给定的字符串是否符合我们定义的逻辑,也可以从字符串中获取我们想要的特定部分.它可以迅速地用极简单的方式 ...

  6. iOS 中的 HotFix 方案总结详解

    相信HotFix大家应该都很熟悉了,今天主要对于最近调研的一些方案做一些总结.iOS中的HotFix方案大致可以分为四种: WaxPatch(Alibaba) Dynamic Framework(Ap ...

  7. iOS中使用正则

    一.什么是正则表达式 正则表达式,又称正规表示法,是对字符串操作的一种逻辑公式.正则表达式可以检测给定的字符串是否符合我们定义的逻辑,也可以从字符串中获取我们想要的特定部分.它可以迅速地用极简单的方式 ...

  8. IOS中div contenteditable=true无法输入

    在IOS中<div contenteditable="true"></div>中点击时可以弹出键盘但是无法输入.加一个样式-webkit-user-sele ...

  9. 谈谈iOS中的屏幕方向

    众所周知,iOS中提供了[UIDevice currentDevice].orientation与[UIApplication sharedApplication].statusBarOrientat ...

随机推荐

  1. go语言之进阶篇定时器停止

    1.定时器停止 示例: package main import ( "fmt" "time" ) func main() { timer := time.New ...

  2. Linux下的串口编程实例

    //串口相关的头文件  #include<stdio.h>      /*标准输入输出定义*/  #include<stdlib.h>     /*标准函数库定义*/  #in ...

  3. 我的四轴专用PID参数整定方法及原理---超长文慎入(转)

    给四轴调了好久的PID,总算是调好了,现分享PID参数整定的心得给大家,还请大家喷的时候手下留情. 首先说明一下,这篇文章的主旨并不是直接教你怎么调,而是告诉你这么调有什么道理,还要告诉大家为什么'只 ...

  4. guns使用注意问题

    guns使用注意问题 1,创建的表必须有注释,这样自动生成代码有标题: 2,必须先构建好结构,后期修改主菜单会产生异常的结构影响: 3,修改菜单编号容易产生异常问题: 4,如果没有id,不会自动生成增 ...

  5. 转: xshell远程连接自动断开的问题解决办法

    转:http://blog.csdn.net/haijiaoqihao20160106/article/details/50623431 2.客户端的配置 Keep Alive修改.我的xshell的 ...

  6. CHtmlEditCtrl(1) : Use CHtmlEditCtrl to Create a Simple HTML Editor

    I needed a lightweight HTML editor to generate "rich text" emails, so I decided to explore ...

  7. [Functional Programming] Daggy

    const daggy = require('daggy'); const {tagged, taggedSum} = daggy; const Coord = daggy.tagged('Coord ...

  8. 关于Chrome浏览器(Chrome Stable、 Chrome Canary 、Chromium)

    作为开发者,web浏览器一般最常用的可能是Chrome浏览器.但其实Chrome浏览器还有别的一些版本.如:Chrome Stable. Chrome Canary .Chromium.大部分人一般用 ...

  9. 【树莓派】树莓派刷Android系统

    树莓派3安装Android TV系统图文教程 http://www.mz6.net/news/android/6866.html 树莓派3 Android TV系统怎样安装?树莓派3一个重要用途就是当 ...

  10. 微信小程序 - 自定义swiper dots样式(非组件)

      自定义须知: :组件内无法使用自定义样式变化,需要自定义 :原理就是利用swiper change事件与下标index匹配,显示不同的样式 swiper组件须知: :一旦swiper用于组件化,就 ...