Masking a progression UIImage

438 views Asked by At

I have a UIImage that I plan on creating a mask for so that when the user continues through the enrollment process they are presented with each number going from non-active, to active, to complete (check mark). I am also creating a "error" sign as well that I would like to place if there is an error. This is sort of like a pageviewcontroller but I don't want to use a pageviewcontroller. They are 5 circles that will change color when active or non, change to a checkmark when complete or a "X" for error. Should I use CGImageMaskCreate or CALayer? This is what I have so far:

func progressImage(name: String) -> 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

}

override func viewDidLoad() { super.viewDidLoad()

//Image array
let image = UIImage(named: "image1.png")
let maskingImage = UIImage(named: "mask1.png")
imageView.image = maskImage(image!, mask:  maskingImage!)

}
0

There are 0 answers