我有一个 UIImage,我计划为其创建一个掩码,以便当用户继续完成注册过程时,他们会看到从非活动到活动到完成的每个数字(复选标记)。我还创建了一个“错误”标志,如果出现错误,我想放置它。这有点像 pageviewcontroller,但我不想使用 pageviewcontroller。它们是 5 个圆圈,在活动或非活动时会改变颜色,完成时会变为复选标记或“X”表示错误。我应该使用 CGImageMaskCreate 还是 CALayer?这是我到目前为止所拥有的:
func progressImage(名称:字符串)-> UIImage {
let stepOne: UIImage = UIImage(named: name)!
print("UIImage 1: \(stepOne.size.width) H\(stepOne.size.height)")
let maskImage: CGImage = stepOne.CGImage!
}
func maskImage(image:UIImage, mask:(UIImage))->UIImage {
let imageReference = image.CGImage
let maskReference = mask.CGImage
let imageMask = CGImageMaskCreate(CGImageGetWidth(maskReference),
CGImageGetHeight(maskReference),
CGImageGetBitsPerComponent(maskReference),
CGImageGetBitsPerPixel(maskReference),
CGImageGetBytesPerRow(maskReference),
CGImageGetDataProvider(maskReference), nil, true)
let maskedReference = CGImageCreateWithMask(imageReference, imageMask)
let maskedImage = UIImage(CGImage:maskedReference!)
return maskedImage
}
覆盖 func viewDidLoad() { super.viewDidLoad()
//Image array
let image = UIImage(named: "image1.png")
let maskingImage = UIImage(named: "mask1.png")
imageView.image = maskImage(image!, mask: maskingImage!)
}