UIImage animationImages tint color?

前端 未结 6 1786
醉话见心
醉话见心 2020-12-31 13:58

Is there a way to tint the images in an animation?

I know I can tint a single image like this:

var imageOne:UIImage = UIImage(named: \"pullto_1.png\"         


        
6条回答
  •  猫巷女王i
    2020-12-31 14:23

    Here is a handy UIImage extension:

    import UIKit
    
    extension UIImage {
    
        func imageWithTint(tint: UIColor) -> UIImage {
            UIGraphicsBeginImageContextWithOptions(size, false, scale)
            let context = UIGraphicsGetCurrentContext()
            CGContextTranslateCTM(context, 0, size.height)
            CGContextScaleCTM(context, 1.0, -1.0)
            CGContextSetBlendMode(context, .Normal)
            let rect = CGRect(origin: .zero, size: size)
            CGContextClipToMask(context, rect, CGImage)
            tint.setFill()
            CGContextFillRect(context, rect)
            let image = UIGraphicsGetImageFromCurrentImageContext()
            UIGraphicsEndImageContext()
            return image;
        }
    
    }
    

提交回复
热议问题