ios 自定义RadioButton
1 前言
众所周知在IOS中没有单选按钮这一控件,今天我们来学习一下简单的单选控件。类似与Web中的radio表单元素。
2 详述
本控件单纯的利用按钮控件和NSObject的respondsToSelector方法来判断某一个类中是否存在某方法。
代码概述:
RadioButton.h(控件头文件):
- #import <UIKit/UIKit.h>
- @protocol RadioButtonDelegate <NSObject>
- -(void)radioButtonSelectedAtIndex:(NSUInteger)index inGroup:(NSString*)groupId;
- @end
- @interface ZYRadioButton : UIView{
- NSString *_groupId;
- NSUInteger _index;
- UIButton *_button;
- }
- //GroupId
- @property(nonatomic,retain)NSString *groupId;
- //Group的索引
- @property(nonatomic,assign)NSUInteger index;
- //初始化RadioButton控件
- -(id)initWithGroupId:(NSString*)groupId index:(NSUInteger)index;
- //为
- +(void)addObserverForGroupId:(NSString*)groupId observer:(id)observer;
- @end
ViewController.m(视图控制器中的代理方法):
- //代理方法
- -(void)radioButtonSelectedAtIndex:(NSUInteger)index inGroup:(NSString *)groupId{
- NSLog(@"changed to %d in %@",index,groupId);
- }
运行结果:
选中某一选项后结果:
控制台显示结果:
2013-05-22 21:50:46.033 RadioButtonDemo[467:c07] changed to 0 in first group
Demo代码下载:http://download.csdn.net/detail/u010013695/5431201
ios 自定义RadioButton的更多相关文章
- 【iOS自定义键盘及键盘切换】详解
[iOS自定义键盘]详解 实现效果展示: 一.实现的协议方法代码 #import <UIKit/UIKit.h> //创建自定义键盘协议 @protocol XFG_KeyBoardDel ...
- Android 自定义RadioButton的样式
Android 自定义RadioButton的样式 我们知道Android控件里的button,listview可以用xml的样式自定义成自己希望的漂亮样式. 最近用到RadioButton,利用xm ...
- Android 自定义RadioButton实现
由于使用小米系统MIUI运行是RadioButton样式跟google Android API自定义的不一样,则我们可以定义任何想要的东东.没有做不到,只有想不到 Android 自定义RadioBu ...
- iOS自定义的UISwitch按钮
UISwitch开关控件 开关代替了点选框.开关是到目前为止用起来最简单的控件,不过仍然可以作一定程度的定制化. 一.创建 UISwitch* mySwitch = [[ UISwitchalloc] ...
- 如何实现 iOS 自定义状态栏
给大家介绍如何实现 iOS 自定义状态栏 Sample Code: 01 UIWindow * statusWindow = [[UIWindow alloc] initWithFrame:[UIAp ...
- 使用自定义RadioButton和ViewPager实现TabHost效果和带滑动的页卡效果
在工作中又很多需求都不是android系统自带的控件可以达到效果的,内置的TabHost就是,只能达到简单的效果 ,所以这个时候就要自定义控件来达到效果:这个效果就是: 使用自定义RadioButto ...
- iOS自定义组与组之间的距离以及视图
iOS自定义组与组之间的距离以及视图 //头视图高度 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(N ...
- iOS 自定义转场动画
代码地址如下:http://www.demodashi.com/demo/12955.html 一.总效果 本文记录分享下自定义转场动画的实现方法,具体到动画效果:新浪微博图集浏览转场效果.手势过渡动 ...
- iOS 自定义转场动画浅谈
代码地址如下:http://www.demodashi.com/demo/11612.html 路漫漫其修远兮,吾将上下而求索 前记 想研究自定义转场动画很久了,时间就像海绵,挤一挤还是有的,花了差不 ...
随机推荐
- IT兄弟连 JavaWeb教程 EL与JSTL表达式经典案例
案例需求:使用MVC模式编写一个程序,当发起一个deptList.do请求时,在servlet中准备一个部门列表对象,把这个列表对象放入request作用域中转发到deptlist.jsp,使用JST ...
- 【OpenJ_Bailian - 4110】圣诞老人的礼物-Santa Clau’s Gifts (贪心)
圣诞老人的礼物-Santa Clau’s Gifts Descriptions: 圣诞节来临了,在城市A中圣诞老人准备分发糖果,现在有多箱不同的糖果,每箱糖果有自己的价值和重量,每箱糖果都可以拆分成 ...
- 模拟ssh、黏包、hashlib模块(MD5)
待补充..... 一.模拟ssh 二.黏包 1.黏包现象 让我们基于tcp先制作一个远程执行命令的程序(命令ls -l ; lllllll ; pwd) res=subprocess.Popen(cm ...
- Longest Palindromic Substring笔记
这是一道在leetcode上看到的题目 一开始,我能想到的思路是蛮力法: 就遍历每个字符,然后对每个字符都尝试从1到n的长度,看有没有回文串,并记录以该字符起始的回文串的最大长度.这个思路其实没有上手 ...
- spring boot使用AbstractXlsView导出excel
一.maven依赖jar包 <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi ...
- [转]POI : How to Create and Use User Defined Functions
本文转自:http://poi.apache.org/spreadsheet/user-defined-functions.html How to Create and Use User Define ...
- Vue.js中data,props和computed数据
data data 是Vue实例的数据对象.Vue将会将data 的属性转换为 getter/setter, 也就是用Object.defineProperty方法(在官网里面有深入响应式原理里面具体 ...
- “Debug Assertion” Runtime Error on VS2008 VS2010 winhand.cpp
I'm writing a C++ MFC program on VS2008 and I'm getting this "Debug Assertion Error" when ...
- Sencha Touch和jQuery Mobile的比较
第一组-行销和平台支持 Sencha Touch和jQuery Mobile都以HTML5框架著称.jQuery Mobile谦虚的说自己只是内建于所有流行的移动设备平台,而Sencha Touch则 ...
- MySQL字符集和排序介绍
客服端字符集: character_set_client utf8mb4连接字符集: character_set_connection utf8mb4数据库字符集: character_set_dat ...