【代码笔记】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,都把选择框分成两类:复选框和单选按钮,这两类控件无论是外观上还是功能上均有显著差异.例如,在外观方面,复选框是在方框内打勾,而单选按钮是在圆圈内画圆点:在功能方面,复选框允 ...
随机推荐
- Bootstrap+angularjs+MVC3+分页技术+角色权限验证系统
1.Bootstrap使用教程 相关教程: http://www.bootcss.com/components.html 页面使用代码: <script src="@Url.Conte ...
- .NET Core中使用Razor模板引擎
一.简介 在MVC以外的场景中,我们往往需要完成一些模板引擎生成代码或页面的工作:在以前我们一般常用的有Razor.NVeocity.VTemplate.虽然所有的模板系统都具有一些共同特征,但 Ra ...
- ASP.NET MVC系列:控制器的Edit方法
在前面我们已经介绍了如何创建控制器.视图和数据模型,运行之前的项目并打开Movies主页,将鼠标悬停在“编辑”菜单上,你会看到浏览器右下角显示了“编辑”链接的地址
- Entity Framework 实体框架的形成之旅--基于泛型的仓储模式的实体框架(1)
很久没有写博客了,一些读者也经常问问一些问题,不过最近我确实也很忙,除了处理日常工作外,平常主要的时间也花在了继续研究微软的实体框架(EntityFramework)方面了.这个实体框架加入了很多特性 ...
- 他答对一半(打一字)asp.net开源简答题项目
先出个字谜: 他答对一半(打一字) 你猜出来了没? 可以到这个网址答题:http://m.hovertree.com/miyu/bjae/4fpmm2td.htm 看你的答案是否正确. 这是ASP.N ...
- css3代码让页面倾斜
教大家一个方法使用CSS把整个网页倾斜,代码只有在支持CSS3.0的浏览器上有效果.目前只有IE9以上版本及firefox高版本支持,其它浏览器没有测试.代码如下 body{ -webkit-tran ...
- C#写快速排序
//先上快排代码------------------------------------------------------------------------public static void Q ...
- css3很美的蟠桃动画
查看效果:http://hovertree.com/texiao/css3/26/ 源码下载:http://hovertree.com/h/bjaf/ndhxgfkn.htm 效果图如下: 代码如下: ...
- Kosaraju算法---强联通分量
1.基础知识 所需结构:原图.反向图(若在原图中存在vi到vj有向边,在反向图中就变为vj到vi的有向边).标记数组(标记是否遍历过).一个栈(或记录顶点离开时间的数组). 算法描叙: :对 ...
- PyCharm不能自动import解决方法_PyCharm cannot auto import package troubleshooting
本人起初是用Eclipse+Pydev学习python的,其实也觉得挺好用.不过后来因为同事推荐去试了下PyCharm,就一发不可收拾的爱上了. 严格来说,题目上的问题其实对于很多人都不算是问题,但是 ...