ios中radiobutton
#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的更多相关文章
- ios中 radioButton和DataPIcker,九宫格封装好使用
下载地址 http://pan.baidu.com/share/link?shareid=2894506499&uk=923776187 引用这几个文件 radiobutton.封装好单选按钮 ...
- ios 自定义RadioButton
1 前言 众所周知在IOS中没有单选按钮这一控件,今天我们来学习一下简单的单选控件.类似与Web中的radio表单元素. 2 详述 本控件单纯的利用按钮控件和NSObject的respondsToSe ...
- 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 ...
随机推荐
- 关于使用rem单位、css函数calc()进行自适应布局
一.关于css中的单位 大家都知道在css中的单位,一般都包括有px,%,em等单位,另外css3新增加一个单位rem. 其中px,%等单位平时在传统布局当中使用的比较频繁,大家也比较熟悉,不过px单 ...
- php7安装mongoDB扩展
本文我们使用pecl命令来安装 首先来到php7的安装目录 $ /usr/local/php7/bin/pecl install mongodb 回车,执行成功后,会输出以下结果: …… Build ...
- Android -- selector&&StateListDrawable
selector <?xml version="1.0" encoding="utf-8" ?> <selector xmlns:androi ...
- Active Learning
怎么办?进行Active Learning主动学习 Active Learning是最近又流行起来了的概念,是一种半监督学习方法. 一种典型的例子是:在没有太多数据的情况下,算法通过不断给出在决策边界 ...
- 强化Linux安全的10个技能
1.找出不必要的服务 很明显,服务器上跑的服务,并不是每个都有用的.强烈建议检查并关掉不需要的服务,从而减少风险(多跑一个服务,就可能多几个漏洞). 查询运行在runlevel 3的服务列表: [af ...
- 如何查看自己电脑系统的安装日期-Window上
开始 > 运行(快捷键 Win+R)->敲入 systeminfo | find “初始安装日期”
- JS构造函数内的方法与构造函数prototype属性上方法的对比
本文的目的是让大家理解什么情况下把函数的方法写在JavaScript的构造函数上,什么时候把方法写在函数的 prototype 属性上;以及这样做的好处. 为了阅读方便,我们约定一下:把方法写在构造函 ...
- Visual Studio 开始支持编写 Android 程序并自带 Android 模拟器【转载】
原文地址 本文内容 为什么需要一个 Android 模拟器 针对 Visual Studio Android 模拟器的调试 Visual Studio Android 模拟器的传感器模拟和其他功能 A ...
- Android studio 自己定义打包APK名称
Android Studio打包应用默认生成的apk名称是:app-release.apk .假设我们要让生成的apk名跟我们版本号包名有联系的话.那我们就要自己定义生成的apk名了,要怎么做呢. 我 ...
- spring boot 启动找不到或无法加载主类
转载:https://www.cnblogs.com/mrray1105/p/8137247.html 刚开始是往上面箭头指出的方向去找问题的原因,但是试了各种方法后问题还是没有解决,于是乎我把焦点转 ...