问题描述
我希望 UIButton 主题类型的圆角矩形部分是我指定的纯色自定义颜色.我明白了
I would like the rounded rectangle portion of the subject type of UIButton to be a solid custom color I specify. I understand that
.setTitleColor : 改变文字颜色.backgroundColor : 改变圆角矩形后面四个饼状角块的颜色
. setTitleColor : changes the text color . backgroundColor : changes the color of the four pie-shaped corner pieces behind the rounded rectangle
问题是如何改变圆角矩形部分的颜色.
The question is how to change the color of the rounded rectangle portion.
我试过setImage,但图像必须有圆角,并且在按钮改变大小时没有任何价值.它不会缩放到新的大小.
I have tried setImage, but the image has to have rounded corners, and is of no value when the button changes size. It does not scale to the new size.
提前致谢.
推荐答案
试试
CALayer *subLayer = [CALayer layer];
subLayer.frame = self.theButton.bounds;
subLayer.cornerRadius = 10.0;
subLayer.opacity = 1.0;
CALayer *imageLayer = [CALayer layer];
imageLayer.frame = subLayer.bounds;
imageLayer.cornerRadius = 10.0;
imageLayer.masksToBounds = YES;
imageLayer.opacity = 1.0;
imageLayer.contents = (id) [UIImage imageNamed:@"your.png"].CGImage;
[subLayer addSublayer:imageLayer];
[self.theButton.layer addSublayer:subLayer];
这篇关于UIButtonTypeRoundedRect 类型的 UIButton 的着色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)