IOS开发(16)之UIButton控件
来源:互联网 发布:艾德纺织软件 编辑:程序博客网 时间:2024/05/17 07:31
1 前言
UIButton为按钮控件,在IOS开发中十分常见,可以为其设置事件。
2 代码实例
ZYViewController.m:
@synthesize myButton;- (void)viewDidLoad{ [super viewDidLoad];// Do any additional setup after loading the view, typically from a nib. self.view.backgroundColor = [UIColor whiteColor]; myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];//设置按钮样式为圆角矩形 myButton.frame = CGRectMake(110.0f, 200.0f, 100.0f, 37.0f); [myButton setTitle:@"Press Me" forState:UIControlStateNormal];//按下按钮时候的标题 [myButton setTitle:@"I'm Pressed" forState:UIControlStateHighlighted];//按下按钮后抬手时候的标题 [myButton addTarget:self action:@selector(buttonIsPressed:) forControlEvents:UIControlEventTouchDown];//按下按钮触发事件 [myButton addTarget:self action:@selector(buttonIsTapped:) forControlEvents:UIControlEventTouchUpInside];//按下按钮后抬手时候触发事件 [self.view addSubview:myButton];}-(void)buttonIsPressed:(UIButton *)paramSender{ NSLog(@"Button is pressed");}-(void)buttonIsTapped:(UIButton *)paramSender{ NSLog(@"Button is tapped");}
运行结果:
点击按钮时候:
2013-04-24 16:00:13.549 UIButtonTest[1635:c07] Button is pressed
2013-04-24 16:00:13.623 UIButtonTest[1635:c07] Button is tapped
ZYUIButtonViewController.m:
- (void)viewDidLoad{ [super viewDidLoad];// Do any additional setup after loading the view, typically from a nib. self.view.backgroundColor = [UIColor whiteColor]; myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];//设置按钮样式为圆角矩形 myButton.frame = CGRectMake(110.0f, 200.0f, 100.0f, 37.0f); [myButton setBackgroundImage:[UIImage imageNamed:@"ok_btn_normal.png"] forState:UIControlStateNormal];//正常状态下时候的标题 [myButton setBackgroundImage:[UIImage imageNamed:@"ok_btn_pressed.png"] forState:UIControlStateHighlighted];//按下按钮时候的标题 [self.view addSubview:myButton];}
运行结果:
点击按钮时候:
3 结语
以上是对UIbutton的简单介绍希望对大家有所帮助。
Demo实例下载:http://download.csdn.net/detail/u010013695/5297459
- IOS开发(16)之UIButton控件
- iOS控件之UIButton
- iOS开发基础控件--按钮(UIButton)
- IOS开发之UIButton
- IOS开发之UIButton
- iOS开发之UIButton
- iOS开发之UIButton
- iOS开发之UIButton
- UIButton按钮控件-iOS开发
- iOS开发基础控件--UIButton
- iOS开发之四:常用控件--UIButton的使用
- iOS控件之UIButton篇
- ios基本控件之UIButton
- iOS UI控件之----UIButton
- 学习ios控件之UIButton
- iOS 开发之设置UIButton(温故知新)
- iOS开发之UIButton(自用贴)
- UIButton 按钮控件-IOS开发 (实例)
- 软件开发实践的24条军规
- nyoj-219
- java基础增强 java新特性 (总结)
- 海量数据面试题整理
- cocos2d-x学习笔记3 Tiled Map Editor地图编辑器
- IOS开发(16)之UIButton控件
- 中兴 FA822升级版本
- 微软安全新闻聚焦-双周刊第三十一期
- Android ViewPager使用详解
- sql打印99乘法表
- 毕业设计首页
- vbs进行正则表达式匹配的方法和需注意的问题
- eclipse工具的使用
- Android实现通用的ActivityGroup(效果类似Android微博客户端主界面),强烈建议不要再使用TabActivity