iOS-动态创建按钮
2015-07-29 14:06
405 查看
// // ViewController.m // 动态创建按钮 // // Created by YaguangZhu on 15/7/29. // Copyright (c) 2015年 YaguangZhu. All rights reserved. // #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; //UIButton *button = [[UIButton alloc] init]; UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem]; [button setTitle:@"hdhdh" forState:UIControlStateNormal]; [button setTitle:@"sss" forState:UIControlStateHighlighted]; [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal]; [button setTitleColor:[UIColor blueColor] forState:UIControlStateHighlighted]; UIImage *imgNormal = [UIImage imageNamed:@"01"]; UIImage *imgHigh = [UIImage imageNamed:@"02"]; [button setBackgroundImage:(imgNormal ) forState:UIControlStateNormal]; [button setBackgroundImage:(imgHigh) forState:UIControlStateHighlighted]; button.frame = CGRectMake(50, 100, 100, 100); //单击事件 [button addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button]; // Do any additional setup after loading the view, typically from a nib. } - (void)buttonClick { NSLog(@"ssss"); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
相关文章推荐
- 27个提升效率的iOS开源库推荐
- IOS应用之间的跳转和数据传
- ios 图片处理( 1.按比例缩放 2.指定宽度按比例缩放
- iOS实现弹幕功能
- iOS自动处理键盘事件的第三方库:IQKeyboardManager
- iOS用AVSpeechSynthesizer合成语音
- iOS开发之如何获取各种控件的输入值
- iOS KVO概述及用法
- iOS 移动开发月报-第1期
- IOS中根据生日精确计算年龄
- 为学IOS,进击中...之OC多态练习
- OAuth认证 / 与新特性页面的配合使用
- iOS视图生命周期
- iOS应用程序生命周期
- IOS修改webView背景透明以及IOS调用前台js的方法
- 定期iOS的后台位置更新-- 相关资料收集,待有时间进行整理
- HDU 1017 A Mathematical Curiosity
- IOS 值得注意的地方
- iOS HTML图片本地预览
- ios 获取屏幕的属性和宽度