Coloration of UIButtons of type UIButtonTypeRoundedRect(UIButtonTypeRoundedRect 类型的 UIButton 的着色)
问题描述
我希望 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 的着色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UIButtonTypeRoundedRect 类型的 UIButton 的着色


基础教程推荐
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- iOS4 创建后台定时器 2022-01-01