Create new iOS system UIImages by tinting any source image
Convert an image asset of any color to appear like a Apple system icon, with these easy extensions. Use icons with no transparent backgrounds for best results!
First, add the familiar "Apple blue" color
extension UIColor {
class func rgb(r: Int, g: Int, b: Int, alpha: CGFloat) -> UIColor{
return UIColor(
red: CGFloat(r) / 255.0,
green: CGFloat(g) / 255.0,
blue: CGFloat(b) / 255.0,
alpha: alpha)
}
class func rgb(r: Int, g: Int, b: Int) -> UIColor{
return self.rgb(r: r, g: g, b: b, alpha: 1.0)
}
class var appleBlue: UIColor {
get {
return UIColor.rgb(r: 0, g: 122, b: 255)
}
}
}
Then use it with this handy tint extension
extension UIImage {
func tint(with color: UIColor) -> UIImage
{
UIGraphicsBeginImageContext(self.size)
guard let context = UIGraphicsGetCurrentContext() else { return self }
context.scaleBy(x: 1.0, y: -1.0)
context.translateBy(x: 0.0, y: -self.size.height)
context.setBlendMode(.multiply)
let rect = CGRect(x: 0, y: 0, width: self.size.width, height: self.size.height)
context.clip(to: rect, mask: self.cgImage!)
color.setFill()
context.fill(rect)
guard let newImage = UIGraphicsGetImageFromCurrentImageContext() else { return self }
UIGraphicsEndImageContext()
return newImage
}
}
Author And Source
この問題について(Create new iOS system UIImages by tinting any source image), 我々は、より多くの情報をここで見つけました https://qiita.com/cayozin/items/b04bcdbd0b8454e9bd1e著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .