//使用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. 别再为了this发愁了:JS中的this机制

    题记:JavaScript中有很多令人困惑的地方,或者叫做机制.但是,就是这些东西让JavaScript显得那么美好而与众不同.比方说函数也是对象.闭包.原型链继承等等,而这其中就包括颇让人费解的th ...

  2. Lucene学习——IKAnalyzer中文分词

    一.环境 1.平台:MyEclipse8.5/JDK1.5 2.开源框架:Lucene3.6.1/IKAnalyzer2012 3.目的:测试IKAnalyzer的分词效果 二.开发调试 1.下载框架 ...

  3. Java 读取某个目录下所有文件、文件夹

    /** * @Author: * @Description:获取某个目录下所有直接下级文件,不包括目录下的子目录的下的文件,所以不用递归获取 * @Date: */ public static Lis ...

  4. Google Guava新手教程

         以下资料整理自网络 一.Google Guava入门介绍 引言 Guavaproject包括了若干被Google的 Java项目广泛依赖 的核心库,比如:集合 [collections] . ...

  5. 根据日期切换图片KFX

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. express next function

    nodejs 里面的next()这个函数调用的作用是什么呢? var express = require('express'); var app = express(); var myLogger = ...

  7. Spark:求出分组内的TopN

    制作测试数据源: c1 85 c2 77 c3 88 c1 22 c1 66 c3 95 c3 54 c2 91 c2 66 c1 54 c1 65 c2 41 c4 65 spark scala实现 ...

  8. Altium Designer 基本封装

    1. 按键的绘制和封装怎么画?如下图: 回答:注意元件的画法不要看错了,封装采用Miscellaneous Devices.IntLib[Footprint View]中的DPST-4 2.蜂鸣器的绘 ...

  9. 推荐一款jQuery ColorPicked 颜色拾取器插件

    先看实现的效果图, 本文底部有完整demo 不想看我墨迹的可以跳过了^_^. 官网地址:http://www.eyecon.ro/colorpicker/#about 代码SVN 地址:https:/ ...

  10. 具体解说Android的图片下载框架UniversialImageLoader之磁盘缓存(一)

    沉浸在Android的开发世界中有一些年头的猴子们,预计都可以深深的体会到Android中的图片下载.展示.缓存一直是心中抹不去的痛.鄙人亦是如此.Ok,闲话不说.为了督促自己的学习.以下就逐一的挖掘 ...