#import <UIKit/UIKit.h>

@protocol RadioButtonExtDelegate;

@interface RadioButtonExt : UIView

- (id)initWithFrame:(CGRect)frame data:(NSArray *)data ;
@property(nonatomic,assign)id<RadioButtonExtDelegate> delegate;
@end @protocol RadioButtonExtDelegate <NSObject> -(void)RadioButton:(RadioButtonExt *)rd from:(NSInteger)from to:(NSInteger)to; @end #import "RadioButtonExt.h"
#import "CommonButton.h"
#define KCount 2//要显示个数
#define KMinTag 100 @interface RadioButtonExt ()
{
CommonButton *_LastExt;
}
@end @implementation RadioButtonExt - (id)initWithFrame:(CGRect)frame data:(NSArray *)data
{
self = [super initWithFrame:frame];
if (self) {
int count=data.count;
int width=frame.size.width/KCount;//没一个宽度
int row=count%==?count/KCount:count/KCount+;//多少行
int height=frame.size.height/row;//每一行的高度
CGRect Rowrec,hrect,rect=self.bounds;
for (int i=; i<row; i++) {
CGRectDivide(rect, &Rowrec, &rect, height, CGRectMinYEdge);//分割row
for (int j=; j<KCount; j++) {
if (KCount*i+j>=count) {//行中个数
break;
}
CGRectDivide(Rowrec, &hrect, &Rowrec, width, CGRectMinXEdge);
CommonButton *rd=[[CommonButton alloc] initWithFrame:hrect];
[rd addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
NSString *normalBg=[[NSBundle mainBundle]pathForResource:@"radio_normal" ofType:@"png"];
NSString *seletctBg=[[NSBundle mainBundle]pathForResource:@"radio_selected" ofType:@"png"]; [rd setImage:[UIImage imageWithContentsOfFile:normalBg] forState:UIControlStateNormal];
[rd setImage:[UIImage imageWithContentsOfFile:seletctBg] forState:UIControlStateSelected];
rd.tag=KMinTag+KCount*i+j;
[rd setTitle:data[KCount*i+j] forState:UIControlStateNormal];
[self addSubview:rd];
}
} }
return self;
} -(void)click:(CommonButton *)btn{
if (_LastExt!=btn) {
_LastExt.selected=NO;
btn.selected=YES; if ([self.delegate respondsToSelector:@selector(RadioButton:from:to:)]) {
[self.delegate RadioButton:self from:_LastExt.tag-KMinTag to:btn.tag-KMinTag];
}
_LastExt=btn;
} }

ios中radiobutton的更多相关文章

  1. ios中 radioButton和DataPIcker,九宫格封装好使用

    下载地址 http://pan.baidu.com/share/link?shareid=2894506499&uk=923776187 引用这几个文件 radiobutton.封装好单选按钮 ...

  2. ios 自定义RadioButton

    1 前言 众所周知在IOS中没有单选按钮这一控件,今天我们来学习一下简单的单选控件.类似与Web中的radio表单元素. 2 详述 本控件单纯的利用按钮控件和NSObject的respondsToSe ...

  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. 集合 enum 枚举 简介 案例 MD

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

  2. What is dependency injection and when/why should or shouldn't it be used?

    参考:https://stackoverflow.com/questions/130794/what-is-dependency-injection 原文:https://www.jamesshore ...

  3. [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 ...

  4. php5.3升级脚本

    在lanmp/wdcp/wdOS的当前版本中,默认的php都是用到5.2.17的版本如需要升级到php5.3的,可使用如下脚本升级(注:此升级无安全漏洞等原因,只为某些追求高版本或应用需求需要高版本, ...

  5. 解决input框中加入disabled="disabled"之后,改变字体的颜色(默认的是灰色)

    在input框中加入disabled="disabled"之后,字体默认的就变成灰色了 解决方案 input[disabled]{color:#fff;opacity:1} dis ...

  6. SpringBoot添加对jsp的支持

    1.在pom.xml添加如下内容: <dependency> <groupId>org.apache.tomcat.embed</groupId> <arti ...

  7. Objective-C编程 - 关于Block的要点

    1. 首先,我们快速过一下,什么是Block? Block是一段代码,它在OC中以^开头,可以有返回值,和参数列表,但就是没有名字. 所以,你可以把它认为是匿名函数. 事实上,它和Swift中的闭包( ...

  8. Python小任务 - 如何编写指定时间执行的Python小程序

    我们在平时的工作中经常会遇到这样的需求,需要再某个时间点执行一段程序逻辑. 那么,在python中我们是怎么做的呢? 下面看代码: waitDesignatedTimeToRun.py import ...

  9. 论asp.net out、ref、return

    论asp.net out.ref.return ref(引用类型) ref引用类型进出都必须赋值,赋值后会改变类型原来的指针. out(值类型) out值类型进可以不赋值,出必须赋值. return( ...

  10. 通过adb命令在Android设备中执行Java命令, 并调用so文件。

    一.难点一:无法复制so文件到/system/lib或者/vendor/lib下,提示只读 解决方法: 2.使用android device monitor放库进入到 /system/lib出现只读权 ...