简体   繁体   English

如何以编程方式设置UIView背景

[英]how to set UIView background programmatically

in the interface builder,i can find the background tag,and select the color and the opacity. 在界面构建器中,我可以找到背景标签,然后选择颜色和不透明度。

if I create the UIView programmatically,if I want to change color,I can set the backgroundColor property 如果我以编程方式创建UIView,如果要更改颜色,则可以设置backgroundColor属性

the question is if I want to change the opactiy,What is the property should I change? 问题是我是否要更改眼镜,我应该更改什么属性?

Thanks a lot. 非常感谢。

使用视图的alpha属性,或者,如果您不希望视图的内容具有相同的不透明度更改,请更改背景颜色的alpha分量(如使用+colorWithRed:green:blue:alpha:+colorWithHue:saturation:brightness:alpha:+colorWithWhite:alpha:以外的其他值。

You can just use 你可以用

self.alpha = someFloat;

in your view class. 在您的视图类中。

If you want to change it from viewcontroller, use 如果要从viewcontroller更改它,请使用

self.view.alpha = someFloat;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM