Emi*_*Adz 2 mask uiimageview uiimage ios swift
我想在运行时将白色图标变为另一种颜色,我试图使用从这里采取的方法,但没有成功:
func maskImageView() {
var maskImageSize = CGSizeMake(self.downloadImageView.frame.width, self.downloadImageView.frame.height)
UIGraphicsBeginImageContextWithOptions(maskImageSize, false, 0.0)
var color = UIColor(white: 1.0, alpha: 1.0)
color.setFill()
var rect = CGRectMake(0, 0, self.downloadImageView.frame.width, self.downloadImageView.frame.height)
UIRectFill(rect)
color = BrandColors.BRAND_FIRST_COLOR
color.setFill()
rect = CGRectMake((self.downloadImageView.frame.width/2)-100, (self.downloadImageView.frame.height/2)-100, 200, 200)
UIRectFill(rect)
var maskImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
var maskLayer = CALayer()
maskLayer.frame = CGRectMake(0, 0, self.downloadImageView.bounds.width, self.downloadImageView.bounds.height)
maskLayer.contents = maskImage.CGImage
maskLayer.contentsRect = CGRectMake(0, 0, self.downloadImageView.bounds.width, self.downloadImageView.bounds.height)
self.downloadImageView.layer.mask = maskLayer;
}
Run Code Online (Sandbox Code Playgroud)
我实际上无法弄清楚这个掩盖的东西是如何工作的.我究竟做错了什么?
我能够使用以下方法完成此任务:
func maskDownloadImageView() {
downloadImageView.image = downloadImageView.image?.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)
downloadImageView.tintColor = BrandColors.BRAND_FIRST_COLOR
}
Run Code Online (Sandbox Code Playgroud)
没有必要使用掩蔽.
| 归档时间: |
|
| 查看次数: |
2413 次 |
| 最近记录: |