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 ...
随机推荐
- Java中 CopyOnWriteArrayList 的使用
java中,List在遍历的时候,如果被修改了会抛出java.util.ConcurrentModificationException错误. 看如下代码: import java.util.Array ...
- MFC中如何显示颜色选择对话框
其实很简单,使用MFC现有的类CColorDialog 即可实现 核心代码如下: void CCColorDialogView::OnGraphSetting() { CColorDialog m_s ...
- 【Java】Springboot-Quartz-分布式任务调度
Springboot-Quartz-分布式任务调度 springboot 调度 自定义并发_百度搜索 spring-boot @Async 的使用.自定义Executor的配置方法 - CSDN博客 ...
- 解决ThinkPHP的Create方法失效而没有提示错误信息的问题
ThinkPHP中的数据创建Create方法是一个非常有用的功能,它自动根据表单数据创建数据对象(在表字段很多的情况下尤其明显) 但有时候该方法可能并未按照你期望的来工作,比如方法不工作而且还没有提示 ...
- 调用百度、高德地图App,百度地图网页版,App定位
https://www.jianshu.com/p/296a3995adc2 https://blog.csdn.net/qq_26598821/article/details/51087785 ht ...
- [Algorithm] Check for balanced parentheses using stack
Algorithm or program to check for balanced parentheses in an expression using stack data structure. ...
- 海马模拟器连不上ADB的解决方法
http://yunpan.cn/c3xMeYhvVsEIq 访问密码 fa8d先暂时用这个工具吧,官方提供的,不过目前不是最终版,后面会加入到模拟器中 adb connect 127.0.0.1: ...
- 解决jetty runner锁定js
在web.xml中添加 <servlet> <!-- Override init parameter to avoid nasty --> <!-- file locki ...
- php学习实例3
新闻发布管理系统 路由器action.php <!DOCTYPE html> <html> <head> <title> </title> ...
- python网络爬虫 - 设定重试次数内反复抓取
import urllib.request def download(url, num_retries=2): print('Downloading:', url) try: html = urlli ...