ios 如何更改圆角矩形 UIbutton 背景颜色

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8153646/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 15:25:10  来源:igfitidea点击:

how to Change a Rounded Rect UIbutton background color

iphoneiosuibuttonbackground-color

提问by Frade

how to Change UIbutton background color?? I try it on IB, but it doesn't work. only changes it for custom button.

如何更改 UIbutton 背景颜色?我在 IB 上尝试过,但它不起作用。只为自定义按钮更改它。

I would like to change the white color on the rounded rect button.

我想更改圆形矩形按钮上的白色。

Or instead how to make a custom button whit rounded corners

或者如何制作带有圆角的自定义按钮

thanks!

谢谢!

采纳答案by isaac

You may find it difficult to adjust the default button. However you can use any view you want with a custom button.

您可能会发现很难调整默认按钮。但是,您可以通过自定义按钮使用任何您想要的视图。

Here's an article on creating views with rounded corners: http://iphonedevelopment.blogspot.com/2008/11/creating-transparent-uiviews-rounded.html

这是一篇关于创建圆角视图的文章:http: //iphonedevelopment.blogspot.com/2008/11/creating-transparent-uiviews-rounded.html

You also may look at a program called Opacity, which allows you to create a a lot of customized standard iOS interface art/buttons.

您还可以查看一个名为 Opacity 的程序,它允许您创建许多自定义的标准 iOS 界面艺术/按钮。

http://likethought.com/opacity/

http://likethought.com/opacity/

回答by Nikita Sharma Sahu

Rounded rect button's color can be changed to any color with the background color property in IB as well as through coding, but can not change its color to transparent color easily. For that, you better use a custom button with either rounded image or set layer as demonstrated in the example and don't forget to add Quartz Core framework in you project as well as to import it in your class.

圆形矩形按钮的颜色可以通过IB中的背景颜色属性以及通过编码更改为任何颜色,但不能轻易将其颜色更改为透明色。为此,您最好使用带有圆形图像或设置图层的自定义按钮,如示例中所示,并且不要忘记在您的项目中添加 Quartz Core 框架以及将其导入您的类中。

UIBUtton *myBtn = [UIButton buttonWithType:UIbuttonTypeCustom];
myBtn.frame = frame;    //your desired size
myBtn.clipsToBounds = YES;
myBtn.layer.cornerRadius = 5.0f;
[self.view addSubView:myBtn];

回答by medampudi

UIButton *tagButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];

and have a look at this... that my do the trick.. i did it for mine.

看看这个……我做的伎俩……我是为我做的。

回答by Aakil Ladhani

You can use Custom button But for that use the image of button of white rounded corners so it will be look like white round rectangle button

您可以使用自定义按钮但是为此使用白色圆角按钮的图像,因此它看起来像白色圆角矩形按钮

回答by Luis Andrés García

You should use UIButtonTypeCustom, instead of any other.

您应该使用 UIButtonTypeCustom,而不是其他任何类型。

回答by Zoleas

You can use a custom UIButtonwith custom images for backgroundimage for each state. Just make the different states of your rounded button in photoshop for example.

您可以UIButton为每个州的背景图像使用自定义图像。例如,只需在 Photoshop 中制作圆形按钮的不同状态。