我是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>
我的示例代码如下:
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];
原文地址:http://stackoverflow.com/questions/7813379/what-does-receiver-type-calayer-for-instance-message-is-a-forward-declaration
分享到:
相关推荐
ios按钮自定义,扩大响应范围,设置部分圆角,发送验证码倒计时
一句代码设置UIButton的image和title的左右上下布局以及image和title的间距,git地址:https://github.com/Coder-ZJ/ZJCustomButton
UIButton+Badge,通过运行时的方式对UIButton拓展了标签展示功能 .
两种方法设置UIButton文本和图片位置
UIButton的类别或扩展名,用于将纯背景色设置为背景图像。 安装 可可豆 将此添加到您的Podfile pod 'UIButton+BackgroundColor' 用法 导入<UIButton> ,然后可以使用以下命令为您的UIButton设置带有状态的背景色...
UIButton 的图文混排,就一个API 还可以在xib里面实现
CCAnimationBtn 一个UIButton子类,模仿抖音App中点赞按钮的动画效果
uibutton的一些基本使用,简单的属性,再加一些封装
1、可任意调整图片对齐方式 2、显示位置 3、可以设置图片的大小 4、设置泡泡 5、点击状态变更 如有意见请留言,谢谢。
iphone中的基础控件UIButton扩展,自定义UICheckBox, 适合初学者,主要学习自定义UICheckBox的常用属性设置、点击事件、返回所有选中的box索引等
其实这个没什么记的,初始化按钮给按钮分别设置选中时对图片和被选中时的图片,给按钮添加方法,在方法中实现三句话就OK了,下面直接看代码: 首先在.m中声明一个按钮 @property (nonatomic, strong) UIButton *...
自动转换UIButton在Xib设置Title时输入的换行符 Import pod 'UIButton-XibLinesText', '~> 1.0.1' Usage 若只设置了UIControlStateNormal的Title或其它State的Title与UIControlStateNormal不同直接import即可 #...
UIButtonCenterTitleAndImage UIButton+CenterImageAndTitle是UIButton的Category,...UIButton button1 = [UIButton buttonWithType:UIButtonTypeCustom]; button1.frame = CGRectMake(60, 80+i60, kScreenWidth-60*2,
self.button=[UIButton buttonWithType:UIButtonTypeCustom]; [self.button addTarget:self action:@selector(buttonTouchUpInside) forControlEvents:UIControlEventTouchUpInside]; [self.button addTarget:self...
ios 自定义uibutton
通过该类可以任意为UIView/UIButton等控件添加某条边的边框,包括边框大小和颜色
使用一句代码为UIbutton增加不同状态的配置(borderColor, titleLabelFont, backgroundColor,subView) 最新代码请移步github: https://github.com/spWang/UIButton-State 如果在使用过程中发现问题,请联系我,...
UIButton,UILabel文字旋转(倾斜),UIButton,UILabel文字旋转(倾斜)
UIButton 的基本用法 需要注意的是 不能同时设置阴影和圆角 这个和layer有关 不要钻牛角 你到后边就知道了
大家都知道UIButton按钮是IOS开发中最常用的控件,作为IOS基础学习教程知识 ,初学者需要了解其基本定义和常用设置,以便在开发在熟练运用。 一、iOS设置UIButton的字体大小 btn.frame = CGRectMake(x, y, width, ...