#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. query多选下拉框插件 jquery-multiselect(修改)

    其实网上关于该控件的使用教程已经很多了,其中 query多选下拉框插件 jquery-multiselect Jquery多选下拉列表插件jquery multiselect功能介绍及使用 这2个的介 ...

  2. [PowerShell Utils] Automatically Change DNS and then Join Domain

    I would like to start a series of blog posts sharing PowerShell scripts to speed up our solution ope ...

  3. java去除字符串的html标签

    //方法一 public String stripHtml(String content) { // <p>段落替换为换行 content = content.replaceAll(&qu ...

  4. 斯坦福大学CS224d课程目录

    https://www.zybuluo.com/hanxiaoyang/note/404582 Lecture 1:自然语言入门与次嵌入 1.1 Intro to NLP and Deep Learn ...

  5. Kafka:ZK+Kafka+Spark Streaming集群环境搭建(九)安装kafka_2.11-1.1.0

    如何搭建配置centos虚拟机请参考<Kafka:ZK+Kafka+Spark Streaming集群环境搭建(一)VMW安装四台CentOS,并实现本机与它们能交互,虚拟机内部实现可以上网.& ...

  6. Eclipse中GitLab的配置和使用入门

    一.Eclipse中配置GitLab的前提条件 1.1:安装Git客户端 去官网https://git-scm.com/downloads下载合适的版本即可,一般开发环境是windows的就下载win ...

  7. VS2013开发asmx接口返回一个自定义XML

    1:利用XmlDocument生成一个xml文档返回,代码如下 using System;using System.Collections.Generic;using System.Linq;usin ...

  8. Kafka单机环境的部署

    前面说过Kafka集群环境的部署,现在主要说一下在本地测试中Kafka单机环境的部署,和前面一样首先保证zookeeper服务的正常运行,然后解压并释放kafka安装包,并放到指定位置: tar -x ...

  9. linux 查找文件或者服务

    [root@localhost ~]# whereis mysql mysql: /usr/bin/mysql /usr/lib/mysql /usr/share/mysql /usr/share/m ...

  10. archivedDataWithRootObject NSUserDefaults

    archivedDataWithRootObject 存储 BusinessCard *bc = [[BusinessCard alloc] init];   NSUserDefaults *ud = ...