我试图使用"圈下面具"对于具有透明度的png图像。
我试过了:
var image = UIImage(named: "logo")!
image = image.imageWithRenderingMode(.AlwaysTemplate)
self.imageViewLogo.tintColor = UIColor.redColor()
self.imageViewLogo.image = image
如果我的徽标是内部带有黑色猫的透明图像,则此代码会生成相同的图像,但会显示红色的猫。
我的目的是获得红色背景颜色的黑猫。
如何在不缺乏性能的情况下实现这一目标?
答案 0 :(得分:1)
使用此...
image = image.imageWithRenderingMode(.AlwaysTemplate)
将使用图像的非透明部分作为模板,以应用多少色调颜色。
您要做的只是使用标准图像并设置图像视图的背景颜色。
let image = UIImage(named: "logo")!
imageViewLogo.image = image
imageViewLogo.backgroundColor = UIColor.redColor()
对于视图的圆角,使其呈圆形,您可以添加以下内容......
imageViewLogo.layer.cornerRadius = CGRectGetHeight(imageView.frame) * 0.5
imageViewLogo.clipsToBounds = true
将半径为半角的角倒圆,然后将边缘剪切到圆角。
答案 1 :(得分:0)
只需设置图像视图的背景颜色
imageView.tintColor = UIColor.blackColor()
imageView.backgroundColor = UIColor.redColor()
如果您只想使用图片(图片为黑色),您甚至不需要tintColor
进行图片查看,只需将图片的渲染模式设置为.AlwaysOriginal