暫無描述

UIImageExt.swift 2.7KB

    // // 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 outputSize = size * scale let renderer = UIGraphicsImageRenderer(size: outputSize) return renderer.image(actions: {_ in }) } func scaledImage(length: CGFloat, with quality: CGFloat) -> Data? { let edge = size.width > size.height ? size.height : size.width let outputSize = size * (length / edge) let renderer = UIGraphicsImageRenderer(size: outputSize) return renderer.jpegData(withCompressionQuality: quality) { _ in let content = UIGraphicsGetCurrentContext() content?.draw(cgImage!, in: CGRect.init(origin: CGPoint.zero, size: outputSize)) } } } 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 blackBackground: UIImage? { return UIImage(named: "navigation-background-black")?.resizableImage(withCapInsets: UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0), resizingMode: .stretch) } public static var right: UIImage? { return UIImage(named: "navigation-right")?.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) } } struct PhotoDetail { public static var purchaseBackground: UIImage? { return UIImage(named: "purchase-background")?.resizableImage(withCapInsets: UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0), resizingMode: .stretch) } } }