UIButtonTypeRoundedRect 类型的 UIButton 的着色 [英] Coloration of UIButtons of type UIButtonTypeRoundedRect

查看:17
本文介绍了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 的着色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆