iOS-设置UIButton背景色仅对角进行着色 [英] iOS - Setting UIButton background color only colors the corners
问题描述
我正在尝试通过更改按钮的颜色来自定义按钮,但是当我使用其中一种时:
I'm trying to customize my button by changing their colors, but when I use either:
self.loginButton.layer.backgroundColor = [UIColor colorWithRed:0.0 green:157.0/255.0 blue:223.0/255.0 alpha:1.0].CGColor;
或
self.loginButton.backgroundColor = [UIColor colorWithRed:0.0 green:157.0/255.0 blue:223.0/255.0 alpha:1.0];
我得到的就是这个结果:
All I get is this result:
我想做的就是将白色更改为蓝色,知道我做错了吗?
What I want to do is change the white color to blue, any idea what I'm doing wrong?
推荐答案
您正在使用圆形rect按钮,该按钮很难看,而且很难自定义.
You're using a round rect button which is pretty ugly, and pretty hard to customise.
您可以创建自定义类型按钮并使用背景图像,也可以创建自定义类型按钮并四舍五入并自行设置图层的背景色.
You can create a custom type button and use a background image, or create a custom type button and round the corners and set the background colour of the layer yourself.
如果您真的想花哨的话,可以在此处可以使用图层为您提供任意大小的渐变类型按钮,而无需图像文件.
If you want to get really fancy there is a nice tutorial here which can give you any-sized gradient type buttons using layers, no image files required.
这篇关于iOS-设置UIButton背景色仅对角进行着色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!