IOS开源项目(2)之RadioButton单选控件学习
1 前言 众所周知在IOS中没有单选按钮这一控件,今天我们来学习一下简单的单选控件。类似与Web中的radio表单元素。
2 详述 本控件单纯的利用按钮控件和NSObject的respondsToSelector方法来判断某一个类中是否存在某方法。
代码概述:
ZYRadioButton.h(控件头文件):
#import @protocol RadioButtonDelegate -(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
ZYViewController.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
3 结语 以上是所有内容希望对大家有所帮助。
【IOS开源项目(2)之RadioButton单选控件学习】Demo代码下载:http://download.csdn.net/detail/u010013695/5431201
推荐阅读
- 2020-04-07vue中Axios的封装和API接口的管理
- iOS中的Block
- 17|17 关山松 第二课作业#公众号项目# D20
- 探索免费开源服务器tomcat的魅力
- RxJava|RxJava 在Android项目中的使用(一)
- 记录iOS生成分享图片的一些问题,根据UIView生成固定尺寸的分享图片
- 2019-08-29|2019-08-29 iOS13适配那点事
- Hacking|Hacking with iOS: SwiftUI Edition - SnowSeeker 项目(一)
- iOS面试题--基础
- 靠QQ月入上万灰色暴利偏门的项目