转-UIButton定义和设置圆角
//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];//边框宽度
*/
原文:http://blog.csdn.net/like7xiaoben/article/details/7588551
转-UIButton定义和设置圆角的更多相关文章
- iOS之用xib给控件设置圆角、边框效果
xib中为各种控件设置圆角 通过代码的方式设置 @interface ViewController () @property (weak, nonatomic) IBOutlet UIView *my ...
- iOS图片设置圆角
一般我们在iOS开发的过程中设置圆角都是如下这样设置的. imageView.clipsToBounds = YES; [imageView.layer setCornerRadius:]; 这样设置 ...
- WPF 自定义TextBox带水印控件,可设置圆角
一.简单设置水印TextBox控件,废话不多说看代码: <TextBox TextWrapping="Wrap" Margin="10" Height=& ...
- iOS图片设置圆角性能优化
问题 圆角虽好,但如果使用不当,它就是你的帧数杀手,特别当它出现在滚动列表的时候.下面来看圆角如何毁掉你的流畅度的. 实测 layer.cornerRadius 我创建了一个简单地UITableVie ...
- Swingr的JTextField、JPasswordField设置圆角输入框
方法1:定义Border,然后给JTextField设置即可 摘自并整理:https://blog.csdn.net/u012093968/article/details/39316679 最好添加这 ...
- iOS之分别使用代码和storyboard、xib为控件设置圆角(以按钮为例)
首先我们看一下代码是如何给按钮设置圆角的: 我们再来看看如何在storyboard或xib中给按钮设置圆角: 1.在storyboard或xib中添加按钮后,设置标题和背景色,做好约束: 2.点击 S ...
- iOS UIView设置圆角
UIView设置圆角 1.比较简单的情况,UIView四个角都是圆角: UIView *aView = [[UIView alloc] init]; aView.frame = CGRectMake( ...
- iOS设置圆角矩形和阴影效果
1.设置圆角矩形 //设置dropview属性 _dropView.backgroundColor=[[UIColor whiteColor] colorWithAlphaComponent:0.8] ...
- Java 图片设置圆角(设置边框,旁白)
/** * 图片设置圆角 * @param srcImage * @param radius * @param border * @param padding * @return * @throws ...
随机推荐
- LeetCode 283 Move Zeroes(移动全部的零元素)
翻译 给定一个数字数组.写一个方法将全部的"0"移动到数组尾部.同一时候保持其余非零元素的相对位置不变. 比如,给定nums = [0, 1, 0, 3, 12],在调用你的函数之 ...
- react-redux 之 provider 和 connect
1.Provider 提供的是一个顶层容器的作用,实现store的上下文传递 2.connect 可以把state和dispatch绑定到react组件,使得组件可以访问到redux的数据 react ...
- HDU1542Atlantis(扫描线)
HDU1542Atlantis(扫描线) 题目链接 题目大意:给你n个覆盖矩形,问最后覆盖的面积. 解题思路:将每一个矩形拆成两条线段,一条是+1的,还有一条是减1的.然后扫描先从上往下扫描,碰到加1 ...
- 【转载】企业服务总线Enterprise service bus介绍
企业服务总线(Enterprise service bus). 以往企业已经实现了很多服务, 构成了面向服务的架构,也就是我们常说的SOA. 服务的参与双方都必须建立1对1 的联系,让我们回顾一下SO ...
- Making User-Managed Backups-17.3、Making User-Managed Backups of Offline Tablespaces and Datafiles
17.3.Making User-Managed Backups of Offline Tablespaces and Datafiles 备份离线的表空间时.须要注意下面指导原则: (1)不能离线s ...
- centos7 rpm 安装MySQL5.6
系统centos7,安装MySQL,出错,百度了一大堆,几乎都是通过yum安装的MySQL,我想说的是,通过yum自动安装的话系统自己会帮你做很多事情,相关联的包也会下下来,相当于替你省去了很多事情, ...
- 堆排序C++实现
//heap sort //堆排序能够分为两个过程.其一是建堆.其二是出堆 //堆是一种全然二叉树,所以它能够用数组进行存储. //堆可分为最大堆和最小堆.最大堆指任一节点的值都大于其左右孩子节点的值 ...
- 下面forward和redirect的描述,正确的是(ABCD)
A:forward是服务器将控制权转交给内部服务器对象,由新的对象来全权负责响应用户的请求 B:执行forward时,浏览器不知道服务器所发送的内容从那里来,浏览器地址栏中还是原来的地址 C:执行re ...
- Koa2学习(二)async/await
Koa2学习(二)async/await koa2中用到了大量的async/await语法,要学习koa2框架,首先要好好理解async/await语法. async/await顾名思义是一个异步等待 ...
- 1分钟看完 jQuery UI
jQuery UI简介 jQuery UI包含了许多维持状态的小部件(Widget),因此,它与典型的 jQuery 插件使用模式略有不同.所有的 jQuery UI 小部件(Widget)使用相同的 ...