UIButtonTypeRoundedRect 类型的 UIButton 的着色

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How to stop UIBarButtonItem text from truncating?(如何阻止UIBarButtonItem文本被截断?)
java.lang.IllegalStateException: SimpleTypeImpl should not be created for error type(异常:不应为错误类型创建SimpleTypeImpl)
Swift: Setting StatusBar color on IOS13+ (Using statusBarManager)(SWIFT:在IOS13+上设置StatusBar颜色(使用statusBarManager))
Android IllegalArgumentException: The tag for fragment_XXX is invalid. Received: layout-sw600dp/fragment_XXX_0(Android IlLegalArgumentException:Fragment_XXX的标签无效。收到:Layout-sw600dp/Fragment_XXX_0)
iOS convert audio sample rate from 16 kHz to 8 kHz(IOS将音频采样率从16 kHz转换为8 kHz)