星空网 > 软件开发 > 操作系统

【代码笔记】单项选择框

一,效果图。

【代码笔记】单项选择框images/loading.gif' data-original="http://images2015.cnblogs.com/blog/337518/201510/337518-20151013140251663-1431419085.jpg" width="218" height="400" />

二,工程图。

【代码笔记】单项选择框

三,代码。

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 = 12015-10-13 13:59:33.921 选择框[7842:203451] self.type = 22015-10-13 13:59:34.569 选择框[7842:203451] self.type = 12015-10-13 13:59:35.345 选择框[7842:203451] self.type = 02015-10-13 13:59:36.897 选择框[7842:203451] self.type = 1

 




原标题:【代码笔记】单项选择框

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

2022东南亚主要跨境电商平台流量分析:https://www.goluckyvip.com/news/7778.html
外贸行业中出口样品报关如何安排?:https://www.goluckyvip.com/news/7779.html
德邦快递发布2018年年报,营收230.25亿,净利润4.56亿:https://www.goluckyvip.com/news/778.html
Shopee、Lazada发布义乌快递应对方案;DHL开通货运新航线!:https://www.goluckyvip.com/news/7780.html
突发!油罐爆炸导致多个亚马逊仓库被迫关闭 :https://www.goluckyvip.com/news/7781.html
天猫淘宝推出“跨境供货平台”;Shopee多个国家佣金等费率上涨 :https://www.goluckyvip.com/news/7782.html
海外KOL推广:与潮流文化共舞,打造年轻态时尚品牌形象:https://www.xlkjsw.com/news/92295.html
DTC个护品牌Svish Ropes完成新一轮融资:https://www.kjdsnews.com/a/1842223.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流