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

【代码笔记】单项选择框

一,效果图。

【代码笔记】单项选择框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 (#换成@)。

货代空运:https://www.goluckyvip.com/tag/102740.html
阳江空运:https://www.goluckyvip.com/tag/102741.html
空运东西:https://www.goluckyvip.com/tag/102742.html
海南空运物流:https://www.goluckyvip.com/tag/102743.html
包头空运价格:https://www.goluckyvip.com/tag/102744.html
货运 空运:https://www.goluckyvip.com/tag/102745.html
丽人丽妆2023年扭亏为盈 玉容初、美壹堂等自有品牌增速超40% :https://www.kjdsnews.com/a/1836576.html
一天拿下10万美金预售!深圳大卖出海第一年成为亚马逊供应商:https://www.kjdsnews.com/a/1836577.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流