一,效果图。

二,工程图。

三,代码。

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-单项选择框的更多相关文章

  1. JavaScript学习笔记之下拉选择框的操作

    对于下拉框的操作十分繁多,这几天项目须要就总结一下 一.动态构建option 有时候我们须要动态构建下拉选择框里面的值,这里我们就要用到 var varItem = new Option(" ...

  2. 【代码笔记】iOS-先选择城市,然后,跳转Tabbar

    一,效果图. 二,工程图. 三,代码. ChooseCityViewController.h #import <UIKit/UIKit.h> @interface ChooseCityVi ...

  3. 【代码笔记】Web-ionic单选框

    一,效果图. 二,代码. <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...

  4. 左右选择框 js插件

    随着项目的进展,测试工程师在更多的浏览器中兼容性测试中,发现有些浏览器不支持option的触发事件,这就造成了先前一篇博文bootstrap 左右框多项选择示例 中左右选择框的失效,于是我就由原先的s ...

  5. 【代码笔记】iOS-时间选择框

    一, 效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewControlle ...

  6. 【代码笔记】iOS-点击出现选择框

    一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...

  7. 【代码笔记】iOS-自定义选择框

    一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> #import "CYCustomMultiSe ...

  8. Java开发笔记(一百二十二)AWT选择框

    前面介绍了两种文本输入框的用法,不过实际应用很少需要用户亲自文字,而是在界面上列出几个选项,让用户勾勾点点完成选择,这样既方便也不容易弄错.依据选择的唯一性,可将选项控件分为两类:一类是在方框中打勾的 ...

  9. Java开发笔记(一百三十)Swing的选择框

    不管是AWT还是Swing,都把选择框分成两类:复选框和单选按钮,这两类控件无论是外观上还是功能上均有显著差异.例如,在外观方面,复选框是在方框内打勾,而单选按钮是在圆圈内画圆点:在功能方面,复选框允 ...

随机推荐

  1. 六、GAIA

    1.      GAIA CSR GAIA (Generic Application Interface Architecture)提供了一个端到端的,与主机无关的生态系统来实现主机应用程序对设备的功 ...

  2. C# 目录(文件夹)复制实现

    private static void CopyDir(DirectoryInfo origin, string target) { if (!target.EndsWith("\\&quo ...

  3. Oracle创建用户、表空间并设置权限

    代码: //dba账户登录 sqlplus 请输入用户名:dpp_data as sysdba 请输入口令:dpp_data //创建账号 create user techrpt_data ident ...

  4. Unicode中文和特殊字符的编码范围

    编程中有时候需要用到匹配中文的正则,一般用 [ \u4e00-\u9fa5]+ 即可搞定.不过这正则对一般的火星文鸟语就不太适用了,甚至全角的标点符号都不包含在内.例如游戏里面的玩家名,普通青年一般都 ...

  5. 利用chrome调试JavaScript代码

    看见网上很多人问怎么用chrome调试JavaScript代码,我也对这个问题抱着疑问,但是没有找到一篇能用的中文文章(可能我的google有问题),也不知道怎么点出一篇E文的,感觉作者写得不错,所以 ...

  6. SQL如何增删修改字段

    1: 新增字段: ) NULL EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'土地手续办理情况' , @level ...

  7. 【Win10开发】关于汉堡菜单-SplitView的用法

    SplitView(汉堡菜单)是win10新加的一种控件,顾名思义,其实就是将视图分割成两部分,废话不多说,下面来介绍一下SplitView的基本用法. 首先介绍几个SplitView经常用到的属性. ...

  8. 基于吉日嘎底层架构的Web端权限管理操作演示-组织机构管理

    软件是服务组织的系统,而任何组织一定会涉及到权限:所以权限控制是一个系统的核心基础,不管你做啥系统都逃不过:有人的地方就有江湖,有系统就有权限管理. 今天我们继续讲一下组织机构的管理: 新增.修改.锁 ...

  9. 不可或缺 Windows Native (15) - C++: 命名空间

    [源码下载] 不可或缺 Windows Native (15) - C++: 命名空间 作者:webabcd 介绍不可或缺 Windows Native 之 C++ 命名空间 示例CppNamespa ...

  10. Wijmo 2016年蓝图

    2015年很快就过去了,这是 Wijmo 重要的一年,尤其是对 Wijmo5.脱离传统的小部件,重新写一套 JS 控件,现在看来这个决定是正确的.用 TypeScript 写 Wijmo5,意味着我们 ...