IOS cut picture fillet package (Swift)

A lot of friends are still rounding out the 2 lines of code.
ha ha, releasing the code today and putting it directly into your project will work. Don’t be laughed at

Direct release of 2 categories,
based SDWebImage package

UIImageView+WebImage.swift / / / / / / / / Created by Jonson on 17/3/13. import UIKit extension UIImage {/ / / / / / / / / / / image to create an avatar - parameter size: - parameter backColor: background color size / / / / / / / / / - returns: trimmed func image ht_avatarImage (size: CGSize, backColor:? UIColor = UIColor.white, lineColor: = UIColor UIColor.lightGray) {var size -> UIImage? Size = if size = = nil {size} = self.size let rect = CGRect (origin: CGPoint), size: (size!) UIGraphicsBeginImageContextWithOptions (rect.size, true, backColor.setFill (0)) UIRectFill (rect) let path = UIBezierPath (ovalIn: rect) (path.addClip) Draw (in: rect) let ovalPath UIBezierPath (ovalIn: = rect) ovalPath.lineWidth = 2 (lineColor.setStroke) ovalPath.stroke (let) = UIGraphicsGetImageFromCurrentImageContext (result) UIGraphicsEndImageContext (return) result} / / / / / / / / / - generated opaque image specifies the size of the parameter size: parameter backColor: - size / / / / / / / / / returns: - background color image (size: func ht_image CGSize? BackColor: = nil, UIColor = UIColor.white ->) {size = VaR; UIImage? Size if size {size} = = nil = self.size let rect = CGRect (origin: (CGPoint), size: size UIGraphicsBeginImageContextWithOptions (REC!) T.size, true, backColor.setFill (0)) UIRectFill (rect) draw (in: rect) let result (UIGraphicsEndImageContext) = UIGraphicsGetImageFromCurrentImageContext (return) result}}

The second

UIImageView+WebImage.swift / / / / / / / / Created by Jonson on 17/3/13. import SDWebImage extension UIImageView {/ / / / / / / / / / / set the image function of isolated SDWebImage - parameter urlString: urlString - parameter placeholderImage: / / / placeholder image - parameter isAvatar: / / / avatar func ht_setImage (urlString: String, placeholderImage: UIImage?? isAvatar:, Bool = false) {/ / guard let urlString URL let = urlString, url = URL (string: urlString else) {/ / set image = placeholderImage return placeholder image} option is used in Swift / OC, sometimes using the same! Can be passed to the nil (with: URL sd_setImage PlaceholderImage:, placeholderImage, options:, Nil) {[weak [], progress: self] (image, _, _, _) in / / completion to determine whether the avatar if isAvatar - {self.Image = image?.ht_avatarImage (size:? Self?.bounds.size)}}}}

Last call

IconView.ht_setImage (urlString:, model.image, placeholderImage:, UIImage (named:, default_image), isAvatar:, true)