纯色圆角按钮
来源:互联网 发布:淘宝按重量设置运费 编辑:程序博客网 时间:2024/06/02 22:26
#define kBtnBackgroundColor [UIColor colorWithRed:73.0/255.0 green:189.0/255.0 blue:204.0/255.0 alpha:1.0]
#define kBtnBackgroundColor1 [UIColor colorWithRed:73.0/255.0 green:200.0/255.0 blue:30.0/255.0 alpha:1.0]
#define kBtnFont [UIFont fontWithName:@"arial" size:17]
//纯色圆角按钮1
UIButton *btnLogin = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];
btnLogin.frame =CGRectMake(30.0,275.0,260.0,45.0);
[btnLogin setBackgroundColor:kBtnBackgroundColor];
btnLogin.layer.cornerRadius =4.0;//关键点,设置btn的圆角大小
btnLogin.titleLabel.font =kBtnFont;
[UIFontfontWithName:@"arial"size:17];
[btnLogin setTitle:@"ok"forState:UIControlStateNormal];
[btnLogin setTintColor:[UIColorwhiteColor]];//关键点,设置btn的文字颜色
[btnLogin addTarget:selfaction:@selector(changePw:)forControlEvents:UIControlEventTouchUpInside];
[self.viewaddSubview:btnLogin];
//纯色圆角按钮2
UIButton *btnLogin1 = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];
btnLogin1.frame =CGRectMake(30.0,200.0,260.0,45.0);
[btnLogin1 setBackgroundColor:kBtnBackgroundColor1];
btnLogin1.layer.cornerRadius =4.0;
btnLogin1.titleLabel.font =kBtnFont;
[UIFontfontWithName:@"arial"size:17];
[btnLogin1 setTitle:@"ok"forState:UIControlStateNormal];
[btnLogin1 setTintColor:[UIColorwhiteColor]];
[btnLogin1 addTarget:selfaction:@selector(changePw:)forControlEvents:UIControlEventTouchUpInside];
[self.viewaddSubview:btnLogin1];
实战
项目中多个地方用到了自定义的圆角矩形,但是我想用XIB来实现自定义的按钮的创建
于是重写UIButton
内容:
- (id)initWithCoder:(NSCoder *)aDecoder
{
if(self == [superinitWithCoder:aDecoder])
{
[selfinitlization];
}
return self;
}
- (void)initlization
{
[selfsetBackgroundColor:kBtnBackgroundColor];
self.layer.cornerRadius =4.0;//关键点,设置btn的圆角大小
[selfsetTintColor:[UIColorblackColor]];//关键点,设置btn的文字颜色
}
在使用时,直接用XIB来拖一个按钮,
使用即可,
现在还有一个问题,那个- (id)initWithCoder:(NSCoder *)aDecoder 方法不点明白,是什么时候才会用到的呢?
- 纯色圆角按钮
- Android Shape自定义纯色圆角按钮
- Android Shape自定义纯色圆角按钮
- Android Shape自定义纯色圆角按钮
- Android Shape自定义纯色圆角按钮
- Android Shape自定义纯色圆角按钮
- Android Shape自定义纯色圆角按钮
- UIColor 直接生成 UIImage 和 圆角纯色UIImage
- 代码生成纯色uiimage
- 东南大学CTF之纯色
- 代码创建纯色UIImage
- UINavigationController添加纯色背景
- 创建纯色图片
- WPF 按钮圆角
- mfc 圆角按钮
- WPF 按钮圆角
- 创建圆角按钮
- 圆角按钮
- Jbehave 学习笔记 (一)
- C++根据png图绘制异性窗口
- SVM入门(一)
- ios--设计模式--抽象工厂模式
- iOS 编译百度地图静态库-合二为一
- 纯色圆角按钮
- Invalid Cross-thread access... bug?
- HTML5/CSS3跨平台开发技术分享(二)
- 喻俨:海豚浏览器在AWS上的最佳实践
- android 之AsyncTask的缺陷与终止
- iOS 遇到问题总结
- 钢管的方式有哪几种?
- QuartusII用自带波形文件做激励进行功能仿真
- poj 2528 Mayor's posters(离散化+线段树)