uttonTypeRoundedRect类型的UIButtons

uttonTypeRoundedRect类型的UIButtons

本文介绍了UIButtonTypeRoundedRect类型的UIButtons的着色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要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类型的UIButtons的着色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 12:03