【代码笔记】iOS-单项选择框
一,效果图。
二,工程图。
三,代码。
RootViewController.h

#import <UIKit/UIKit.h> @interface RootViewController : UIViewController //方便跳转到相应的页面
@property (nonatomic , retain) NSString* type; @end

RootViewController.m

#import "RootViewController.h" @interface RootViewController () @end @implementation RootViewController
{
int butTag;
}
@synthesize type; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
} - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view. self.title=@"选择框"; self.view.backgroundColor=[UIColor orangeColor]; NSArray *array=[NSArray arrayWithObjects:@"学生",@"家长",@"老师", nil];
for (int i = 0; i<3; i++) { //字后面的Label
UILabel *lab=[[UILabel alloc]initWithFrame:CGRectMake(60+80*i, 100, 50, 15)];
[lab setFont:[UIFont systemFontOfSize:15]];
[lab setTextColor:[UIColor grayColor]];
[lab setBackgroundColor:[UIColor clearColor]];
[lab setText:[array objectAtIndex:i]];
[self.view addSubview:lab]; butTag=100 ; //能点击的小圆点按钮
UIButton *but=[UIButton buttonWithType:UIButtonTypeCustom];
[but setFrame:CGRectMake(40+80*i, 100, 15, 15)];
[but setImage:[UIImage imageNamed:@"1"] forState:UIControlStateNormal];
[but setImage:[UIImage imageNamed:@"2"] forState:UIControlStateSelected];
[but addTarget:self action:@selector(choose:) forControlEvents:UIControlEventTouchUpInside];
[but setTag:i+100];
[self.view addSubview:but]; if (butTag == i + 100) {
[but setSelected:YES];
[but setUserInteractionEnabled:NO];
}
} } //选择角色
- (void)choose:(UIButton *)sender{ UIButton *button = (UIButton *)[self.view viewWithTag:butTag];
[button setSelected:NO];
[button setUserInteractionEnabled:YES]; [sender setUserInteractionEnabled:NO];
[sender setSelected:YES]; int intvalue = (int)sender.tag -100;
NSString *typeStr=[NSString stringWithFormat:@"%i",intvalue];
self.type = typeStr;
NSLog(@"self.type = %@",self.type); butTag = (int)sender.tag; } - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

四,输出:
2015-10-13 13:59:33.313 选择框[7842:203451] self.type = 1
2015-10-13 13:59:33.921 选择框[7842:203451] self.type = 2
2015-10-13 13:59:34.569 选择框[7842:203451] self.type = 1
2015-10-13 13:59:35.345 选择框[7842:203451] self.type = 0
2015-10-13 13:59:36.897 选择框[7842:203451] self.type = 1
【代码笔记】iOS-单项选择框的更多相关文章
- JavaScript学习笔记之下拉选择框的操作
对于下拉框的操作十分繁多,这几天项目须要就总结一下 一.动态构建option 有时候我们须要动态构建下拉选择框里面的值,这里我们就要用到 var varItem = new Option(" ...
- 【代码笔记】iOS-先选择城市,然后,跳转Tabbar
一,效果图. 二,工程图. 三,代码. ChooseCityViewController.h #import <UIKit/UIKit.h> @interface ChooseCityVi ...
- 【代码笔记】Web-ionic单选框
一,效果图. 二,代码. <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...
- 左右选择框 js插件
随着项目的进展,测试工程师在更多的浏览器中兼容性测试中,发现有些浏览器不支持option的触发事件,这就造成了先前一篇博文bootstrap 左右框多项选择示例 中左右选择框的失效,于是我就由原先的s ...
- 【代码笔记】iOS-时间选择框
一, 效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewControlle ...
- 【代码笔记】iOS-点击出现选择框
一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...
- 【代码笔记】iOS-自定义选择框
一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> #import "CYCustomMultiSe ...
- Java开发笔记(一百二十二)AWT选择框
前面介绍了两种文本输入框的用法,不过实际应用很少需要用户亲自文字,而是在界面上列出几个选项,让用户勾勾点点完成选择,这样既方便也不容易弄错.依据选择的唯一性,可将选项控件分为两类:一类是在方框中打勾的 ...
- Java开发笔记(一百三十)Swing的选择框
不管是AWT还是Swing,都把选择框分成两类:复选框和单选按钮,这两类控件无论是外观上还是功能上均有显著差异.例如,在外观方面,复选框是在方框内打勾,而单选按钮是在圆圈内画圆点:在功能方面,复选框允 ...
随机推荐
- C#串口通信—向串口发送数据,同步接收返回数据
最近写C#串口通信程序,系统是B/S架构.SerialPort类有一个DataReceived事件,用来接收串口返回的数据,但这种方式在C/S架构下很好用,但B/S就不好处理了.所以写了一个同步模式接 ...
- DataTable转换为List<T>或者DataRow转换为T
这段时间开发ASP.NETMVC应用程序,从数据库获取数据之后,需要把记录转换为数据集在视图中显示.我们需要把DataTable转换为List<T>或者DataRow转换为T. 本篇中可以 ...
- 一个疑难杂症 IIS URL区分大小写(FF的自动变换URL问题)?
(II8 VS14 CTP3 Windows7 ASP.NET WEBFORM) 在我的印象里面,IIS的URL在一般情况下面是不分大小写的. 所以下面两个URL应该是一样的. http://loca ...
- 【C#】VS2015开发环境的安装和配置(二)2016-08-03更新
分类:C#.VS2015.WPF.ASP.NET MVC.Android.iOS.Unity3D: 更新日期:2016-08-03 按下面介绍的步骤安装即可. 一.安装JDK和Android SDK ...
- js设置和读取cookie
/*path参数:表示cookie所在的目录,.net默认为/(根目录).在同一个服务器上有目录如下:/test/,/test/aa/,/test /bb/,现设一个cookie1的path为/tes ...
- 用于PHP的Gearman Worker管理工具GearmanManager
项目地址:https://github.com/brianlmoon/GearmanManager PHP环境要求 PHP 5.5.9 POSIX extension Process Control ...
- Gitblit中采用Ticket模式进行协作开发
Git目前的代码分支管理模型中,比较主要的有Git-Flow.Github Pull Request.大家日常或多或少都在用着. 在不想安装Gitlab这种重量级的环境的情况下,如果是利用git一步步 ...
- [moka同学笔记]Yii2.0给一张表中增加一个属性
1.model中建立关联 public function getUser(){ return$this->hasOne(User::className(),['id'=>'uid']) ; ...
- shiro realm 注解失败问题解决过程
做为一名在.net混了八九年的老兵油子,转战java时间并不长,刚开始做项目完全是凭借对C#的认识来做,虽然遇到一些问题,但实际结果显示C#在语言上和java还是有很大相似度,而且微软的MVC与Spr ...
- 初识orcl
一.介绍基本数据库的端口号. SQLServer 端口号:1433 MySql 端口号:3306 Oracle ...