想要将UIButton设置背景色
2013-07-31 15:20
246 查看
我是ios开发新手。
今天遇到一个问题,想要将UIButton设置背景色,结果发现只有将Type设置为UIButtonTypeCustom时,背景色才起作用。
但是此时,圆角效果却木有了……。网上搜索了半天,基本上都说通过layer的几个方法设置,但是copy代码后报错“Receivertype 'CALayer'forinstance message is a forward declaration”。
最后从一个老外的帖子里找到答案:
Add QuartzCore.framework to your project and this line to your .m file.
#import
<QuartzCore/QuartzCore.h>
我的示例代码如下:
Ios代码
UIButton *moreButton = [UIButton buttonWithType:UIButtonTypeCustom];
moreButton.frame = CGRectMake(1.0f, 1.0f, cell.contentView.frame.size.width-2, cell.contentView.frame.size.height-2);
[moreButton.layer setMasksToBounds:YES];
[moreButton.layer setCornerRadius:10.0]; //设置矩形四个圆角半径
[moreButton.layer setBorderWidth:1.0]; //边框宽度
moreButton.backgroundColor = [UIColor clearColor];
今天遇到一个问题,想要将UIButton设置背景色,结果发现只有将Type设置为UIButtonTypeCustom时,背景色才起作用。
但是此时,圆角效果却木有了……。网上搜索了半天,基本上都说通过layer的几个方法设置,但是copy代码后报错“Receivertype 'CALayer'forinstance message is a forward declaration”。
最后从一个老外的帖子里找到答案:
Add QuartzCore.framework to your project and this line to your .m file.
#import
<QuartzCore/QuartzCore.h>
我的示例代码如下:
Ios代码
UIButton *moreButton = [UIButton buttonWithType:UIButtonTypeCustom];
moreButton.frame = CGRectMake(1.0f, 1.0f, cell.contentView.frame.size.width-2, cell.contentView.frame.size.height-2);
[moreButton.layer setMasksToBounds:YES];
[moreButton.layer setCornerRadius:10.0]; //设置矩形四个圆角半径
[moreButton.layer setBorderWidth:1.0]; //边框宽度
moreButton.backgroundColor = [UIColor clearColor];
相关文章推荐
- ios UIButton设置高亮状态下的背景色
- UIButton的边框颜色设置
- 统一设置Swing组件的背景色和字体
- QPalette类,主要用来设置控件背景色和前景色
- wpf datagrid设置右键菜单打开时选中项的背景色
- 设置DataGridView行背景色
- 文本框字体色,对话框和静态文件背景色设置方法(OnCtlColor消息)
- javascript如何设置DIV背景色为随机色
- 如何设置richedit的默认背景色和文字颜色
- Swing之JTree篇:设置树选中节点背景色
- android listview item 被选中背景色设置
- 生成随机图片的方法----图片背景色的设置
- ListView中设置item的背景色后,默认的行点击颜色失效的解决办法
- 关于Qt使用QPalette设置Qwidget背景色无效的解决办法及分析
- jquery css 设置table的奇偶行背景色示例
- eclipse如何设置成保护眼的背景色
- 转,,,,C#中关于DataGridView行和列的背景色-前景色设置
- C# WinForm 设置按纽为透明,使用背景色
- listview当选中某一个item时设置背景色其他的不变
- 设置UIButton的image title 位置