iOS 用for循环写了一排button
2016-01-15 16:20
344 查看
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
float x = 20;
float y = 100;
float w = 30;
float h = 30;
for (int i = 0; i<5; i++) {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
[btn setFrame:CGRectMake(w*i+x, y, w, h)];
btn.backgroundColor = [UIColor redColor];
[btn setTitle:[NSString stringWithFormat:@"%d",i] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(btn_click:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
}
- (void)btn_click:(id)sender
{
UIButton *btn = sender;
btn.backgroundColor = [UIColor greenColor];
}
是这个意思么。点了变颜色了。
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
float x = 20;
float y = 100;
float w = 30;
float h = 30;
for (int i = 0; i<5; i++) {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
[btn setFrame:CGRectMake(w*i+x, y, w, h)];
btn.backgroundColor = [UIColor redColor];
[btn setTitle:[NSString stringWithFormat:@"%d",i] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(btn_click:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
}
- (void)btn_click:(id)sender
{
UIButton *btn = sender;
btn.backgroundColor = [UIColor greenColor];
}
是这个意思么。点了变颜色了。
相关文章推荐
- 关于iOS9之后 获取用户是否安装sim卡 的方法
- 160115iOS多线程中performSelector: 和dispatch_time的不同
- iOS利用Runtime自定义控制器POP手势动画
- iOS-生命周期
- iOS设置Label上显示不同字体大小
- CGContext小记
- iOS 自动化生成API文档
- iOS傻金币动画
- 干货!总结19个提升iOS开发技术的必看教程!
- iOS开发正则表达式判断邮箱是否合法
- ios开发首次安装或者版本升级的引导页的判断
- mac 终端 svn 命令ios
- 以下是unix的命令行,供参考 ios
- iOS开发判断身份证号是否合法
- ios 定位是否可用的判断
- NSURLSession断点续传
- 命令行操作ios
- 需求 - 4 - 滚动广播文字 - 2
- IOS 检查版本更新
- 干货!总结19个提升iOS开发技术的必看教程!