使用UIButton
2015-07-10 09:12
387 查看
//login button
// .h 中定义
UIButton *_loginBtn;
@property (strong,nonatomic)UIButton *loginBtn;
// .m 中实现设置按钮
@synthesize loginBtn = _loginBtn;//使用备份变量名
//设置按钮的 形状
self.loginBtn
4000
= [UIButton buttonWithType:UIButtonTypeRoundedRect];
/*
buttonWithType: 定义button按钮的外形
六种定义button类型: 下面有图解
UIButtonTypeCustom = 0, 无类型
UIButtonTypeRoundedRect, 四个角是圆弧 型的
UIButtonTypeDetailDisclosure,
UIButtonTypeInfoLight,
UIButtonTypeInfoDark,
UIButtonTypeContactAdd,
*/
//定义button按钮在frame上的坐标(位置),和这个按钮的宽/高
self.loginBtn.frame = CGRectMake(40, 200, 80, 30);
[self.loginBtn setTitle:@"Login" forState:UIControlStateNormal];
/*
常用的属性:
setTitle: 设置button按钮的名称
setImage: [UIImage imageNamed:@"图名"] 添加图片
setTitleColor:[UIColor redColor] 设置字体颜色
forState 设置 按钮点击前后的状态 : 下有图解
UIControlStateHighlighted
UIControlStateSelected
UIControlStateDisabled
UIControlStateNormal
*/
// 为按钮添加一个动作
// action: 如果点击的话执行的方法
[self.loginBtn addTarget:self action:@selector(Login:) forControlEvents:UIControlEventTouchUpInside];
//把button控件添加到view中显示
[self.view addSubview:self.loginBtn];
[cpp] view
plaincopy
//执行动作的方法
-(IBAction)Login:(id)sender;
六种定义button类型:
UIButtonTypeCustom = 0, 无类型
UIButtonTypeRoundedRect, 四个角是圆弧 型的
UIButtonTypeDetailDisclosure
UIButtonTypeInfoLight
UIButtonTypeInfoDark
UIButtonTypeContactAdd
forState 设置 按钮点击前后的状态
点击前 点击后
UIControlStateHighlighted
UIControlStateSelected
UIControlStateDisabled
UIControlStateNormal
UIButtonTypeRoundedRect 设置为这个属性,是可以满足我们普通情况下的按钮圆角,当我们在button上添加背景图片和背景颜色的时候就会发现,这个属性并不适用,因为现在的button已经不是圆角的了,它显示的是图片的形状,当设置背景颜色设置为UIButtonTypeCustom属性才可以显示出来。所以我们需要用UIButton控件的其它属性来满足我们的需求
[cpp] view
plaincopy
UIButton *btn;
[btn.layer setMasksToBounds:YES];
[btn.layer setCornerRadius:10.0];//设置矩形四个圆角半径
/*
[btn.layer setBorderWidth:1.0];//边框宽度
*/
// .h 中定义
UIButton *_loginBtn;
@property (strong,nonatomic)UIButton *loginBtn;
// .m 中实现设置按钮
@synthesize loginBtn = _loginBtn;//使用备份变量名
//设置按钮的 形状
self.loginBtn
4000
= [UIButton buttonWithType:UIButtonTypeRoundedRect];
/*
buttonWithType: 定义button按钮的外形
六种定义button类型: 下面有图解
UIButtonTypeCustom = 0, 无类型
UIButtonTypeRoundedRect, 四个角是圆弧 型的
UIButtonTypeDetailDisclosure,
UIButtonTypeInfoLight,
UIButtonTypeInfoDark,
UIButtonTypeContactAdd,
*/
//定义button按钮在frame上的坐标(位置),和这个按钮的宽/高
self.loginBtn.frame = CGRectMake(40, 200, 80, 30);
[self.loginBtn setTitle:@"Login" forState:UIControlStateNormal];
/*
常用的属性:
setTitle: 设置button按钮的名称
setImage: [UIImage imageNamed:@"图名"] 添加图片
setTitleColor:[UIColor redColor] 设置字体颜色
forState 设置 按钮点击前后的状态 : 下有图解
UIControlStateHighlighted
UIControlStateSelected
UIControlStateDisabled
UIControlStateNormal
*/
// 为按钮添加一个动作
// action: 如果点击的话执行的方法
[self.loginBtn addTarget:self action:@selector(Login:) forControlEvents:UIControlEventTouchUpInside];
//把button控件添加到view中显示
[self.view addSubview:self.loginBtn];
[cpp] view
plaincopy
//执行动作的方法
-(IBAction)Login:(id)sender;
六种定义button类型:
UIButtonTypeCustom = 0, 无类型
UIButtonTypeRoundedRect, 四个角是圆弧 型的
UIButtonTypeDetailDisclosure
UIButtonTypeInfoLight
UIButtonTypeInfoDark
UIButtonTypeContactAdd
forState 设置 按钮点击前后的状态
点击前 点击后
UIControlStateHighlighted
UIControlStateSelected
UIControlStateDisabled
UIControlStateNormal
UIButtonTypeRoundedRect 设置为这个属性,是可以满足我们普通情况下的按钮圆角,当我们在button上添加背景图片和背景颜色的时候就会发现,这个属性并不适用,因为现在的button已经不是圆角的了,它显示的是图片的形状,当设置背景颜色设置为UIButtonTypeCustom属性才可以显示出来。所以我们需要用UIButton控件的其它属性来满足我们的需求
[cpp] view
plaincopy
UIButton *btn;
[btn.layer setMasksToBounds:YES];
[btn.layer setCornerRadius:10.0];//设置矩形四个圆角半径
/*
[btn.layer setBorderWidth:1.0];//边框宽度
*/
相关文章推荐
- 使用UIButton
- UGUI 实现界面 渐隐渐现 FadeIn/Out 效果
- 使用UIAlertView
- 使用UIAlertView
- 使用UIActionSheet
- 使用UIActionSheet
- 如何判断NGUI的ScrollView是否正在移动
- Win10 Build 10166 加入Wi-Fi购买 随时随地连Wi-Fi、不断网
- could not build module ‘Foundation’, could not build module ‘UIKit’……23个错误
- could not build module ‘Foundation’, could not build module ‘UIKit’……23个错误
- Windows 10 Build 10166正式推送 允许购买wifi
- Windows 10 Build 10166发布 Groove品牌正式上线
- pkg: cached package *:size mismatch, cannot continue
- iOS中UILabel 多行显示
- druid连接池配置
- Quick中的import
- 上海远丰EXPBuilder助力企业海外电商业务
- 上海远丰EXPBuilder助力企业海外电商业务
- MallBuilder助力企业电商成长
- easyui datetime-box