//使用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. [leetcode]Reverse Linked List II @ Python

    原题地址:https://oj.leetcode.com/problems/reverse-linked-list-ii/ 题意: Reverse a linked list from positio ...

  2. ORM数据库框架 greenDAO SQLite MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  3. springboot 项目mybatis plus 设置 jdbcTypeForNull (oracle数据库需配置JdbcType.NULL, 默认是Other)

    方法1: application.yml mybatis-plus: configuration: jdbc-type-for-null: 'null' #注意:单引号 方法2: 查看mp-start ...

  4. 关于UI设计中的交互软件Axure7.0运用

    Axure RP是一个专业的快速原型设计工具.让负责定义需求和规格.设计功能和界面的人员能够快速创建应用软件或Web网站的线框图.流程图.原型和规格说明文档. 作为专业的原型设计工具,它能快速.高效的 ...

  5. GPUImage简单滤镜使用(二)

    GPUImage中,提供了许多简单的的常用的滤镜.在上一篇文章讲了如何调节图像的亮度这片文章讲一下如何通过GPUImage调节图像的对比度,饱和度,曝光度,和白平衡(美图秀秀中的色温). 原图像 调整 ...

  6. ckeditor 4.2.1_演示 ckeditor 上传&插入图片

    本文内容 FineUI ckeditor fckeditor/ckeditor 演示 ckeditor 4.2.1 上传&插入图片 最近看了一下 FineUI_v3.3.1 控件,对里边的 c ...

  7. 庞果英雄会第二届在线编程大赛·线上初赛:AB数

    题目链接 给定两个正整数a,b,分别定义两个集合L和R, 集合L:即把1~a,1~b中整数乘积的集合定义为L = {x * y | x,y是整数且1 <= x <=a , 1 <= ...

  8. google protocol buffer 简介 版本 安装 使用 实例

    一.简介 protocolbuffer(以下简称PB)是google 的一种数据交换的格式,它独立于语言,独立于平台.google 提供了三种语言的实现:java.c++ 和 python,每一种实现 ...

  9. Suse系统中不使用SFTP的话,还可以使用lrzsz。

    一.安装:zypper install lrzsz 二.发送文件到远程Suse: rz 三.接收文件从远程Suse: sz ./hello.sh

  10. Postgresql中的数据类型大全

    一.数值类型: 下面是PostgreSQL所支持的数值类型的列表和简单说明: 名字 存储空间 描述 范围 smallint 2 字节 小范围整数 -32768 到 +32767 integer 4 字 ...