xcode Swift 为 UIImageView 背景添加透明色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30221528/
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
Swift Add transparent color to UIImageView background
提问by Sameer Hussain
var controllerScreen = UIImageView()
controllerScreen.backgroundColor = UIColor.redColor()
This adds red opaque color to the UIImageView. I want to add a transparent red color. Is there any transparent property or something ?
这会为 UIImageView 添加不透明的红色。我想添加一个透明的红色。有没有透明的财产之类的?
回答by ABakerSmith
As an alternative to @AdamPro13's answer you could do:
作为@AdamPro13 答案的替代方案,您可以执行以下操作:
controllerScreen.backgroundColor = UIColor.redColor().colorWithAlphaComponent(0.5)
回答by AdamPro13
You need to change the alpha value of the red color. You can use something like this: UIColor(red: 1.0, green: 0.0, blue: 0.0, alpha: 0.5)
您需要更改红色的 alpha 值。你可以使用这样的东西:UIColor(red: 1.0, green: 0.0, blue: 0.0, alpha: 0.5)