IOS成长之路-UIButton定义和设置圆角
来源:互联网 发布:阿里云cdn 编辑:程序博客网 时间:2024/05/17 23:07
//login button // .h 中定义 UIButton *_loginBtn; @property (strong,nonatomic)UIButton *loginBtn; // .m 中实现设置按钮 @synthesize loginBtn = _loginBtn;//使用备份变量名 //设置按钮的 形状 self.loginBtn = [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];
//执行动作的方法-(IBAction)Login:(id)sender;
六种定义button类型:
UIButtonTypeCustom = 0, 无类型
UIButtonTypeRoundedRect, 四个角是圆弧 型的
UIButtonTypeDetailDisclosure
UIButtonTypeInfoLight
UIButtonTypeInfoDark
UIButtonTypeContactAdd
forState 设置 按钮点击前后的状态
点击前 点击后
UIControlStateHighlighted
UIControlStateSelected
UIControlStateDisabled
UIControlStateNormal
UIButtonTypeRoundedRect 设置为这个属性,是可以满足我们普通情况下的按钮圆角,当我们在button上添加背景图片和背景颜色的时候就会发现,这个属性并不适用,因为现在的button已经不是圆角的了,它显示的是图片的形状,当设置背景颜色设置为UIButtonTypeCustom属性才可以显示出来。所以我们需要用UIButton控件的其它属性来满足我们的需求
UIButton *btn; [btn.layer setMasksToBounds:YES]; [btn.layer setCornerRadius:10.0];//设置矩形四个圆角半径 /* [btn.layer setBorderWidth:1.0];//边框宽度 */
- IOS成长之路-UIButton定义和设置圆角
- IOS成长之路-UIButton定义和设置圆角
- IOS成长之路-UIButton定义和设置圆角
- IOS成长之路-UIButton定义和设置圆角
- UIButton定义和设置圆角
- UIButton定义和设置圆角
- UIButton定义和设置圆角
- Ios UIButton 设置圆角和边框
- iOS之UIButton设置
- iOS UIView(UIButton)设置圆角和边框
- iOS - UIButton设置圆角和边框及边框颜色
- iOS 使用storyboard设置UIButton 和UILabel 的圆角
- 将视图设置成圆角和阴影添加以及UIButton定义和设置圆角
- iOS 开发之设置UIButton
- iOS给UIButton设置圆角
- iOS - UIButton(UIEdgeInsets)/设置button上的文字和图片 在定义位置
- 28.iOS - UIButton(UIEdgeInsets)/设置button上的文字和图片 在定义位置
- iOS - UIButton(UIEdgeInsets)/设置button上的文字和图片 在定义位置
- Android基本架构分析汇总
- 2012年 上半年 第十三周 C++程序设计 (四十)
- 当好领导者(二)——>领导团队
- 第十四周任务一对象指针
- 一条语句删除全选
- IOS成长之路-UIButton定义和设置圆角
- C++的命名空间
- 关于震动转一篇
- 黑马程序员-java 运行类文件
- 创建空白图像
- ffmpeg av_open_input_file 不能打开文件原因
- C语言多线程实例,VC下使用
- Android开发平台振动器系统详解
- 抽象工厂模式第三步-使用抽象工厂模式