如何以编程方式更改uibutton的背景颜色 [英] How to change backgroundcolor of uibutton programmatically

查看:37
本文介绍了如何以编程方式更改uibutton的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将按钮的背景颜色更改为黑色?

How would I change the background color of a button to black?

推荐答案

如果您想以编程方式更改按钮的颜色,则必须使按钮的类型自定义为:-

If you want to programatically change the colour of button you will have to make the type of button as custom as :-

UIButton *button = [UIButton buttonWithType:uibuttontypecustom];
note "uibuttontypecustom"

然后您可以通过 [btn setBackgroundColor:[UIColor blackColor]]; 更改背景,或者您可以使用 上的 steImage 方法设置黑色背景图像btn.

and then you can change backgroung by [btn setBackgroundColor:[UIColor blackColor]]; or you can set a black backgroung image by using steImage method on btn.

这篇关于如何以编程方式更改uibutton的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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