// // UIImageExt.swift // ExtensionKit // // Created by FFIB on 2017/9/14. // Copyright © 2017年 FFIB. All rights reserved. // import UIKit public extension UIImage { func scaledImage(_ scale: CGFloat) -> UIImage? { let rect = CGRect(x: 0, y: 0, width: self.size.width * scale, height: self.size.height * scale).integral UIGraphicsBeginImageContextWithOptions(rect.size, true, UIScreen.main.scale) self.draw(in: rect) let image = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return image } static func imageWithColor(_ color: UIColor) -> UIImage { let rect = CGRect(x: 0.0, y: 0.0, width: 1.0, height: 1.0) UIGraphicsBeginImageContext(rect.size) let context = UIGraphicsGetCurrentContext() context?.setFillColor(color.cgColor) context?.fill(rect) let image = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return image! } } public extension UIImage { static var defaultAvatar: UIImage? { return UIImage(named: "defaultAvatar") } static var photoPlaceholder: UIImage? { return UIImage(named: "photoPlaceholder") } struct Navigation { public static var background: UIImage? { return UIImage(named: "navigation-background")?.resizableImage(withCapInsets: UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0), resizingMode: .stretch) } public static var verticalPoints: UIImage? { return UIImage(named: "navigation-vertical-points")?.resizableImage(withCapInsets: UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0), resizingMode: .stretch) } } }