import Foundation extension UIImageView { /// 快速创建ImageView /// - Parameters: /// - imageName: 图片名字 /// - supView: 被添加视图 /// - result: ImageView对象 /// - snapKitMaker: 约束 /// - Returns: 对象 @discardableResult public static func reloadCustemImageView(imageName:String? = nil, supView: UIView? = nil, result: ((_ imageView: UIImageView) -> Void)? = nil, snapKitMaker: ((ConstraintMaker) -> Void)? = nil) -> UIImageView { let imageView = UIImageView() imageView.isUserInteractionEnabled = true imageView.contentMode = .scaleAspectFill guard let imageStr = imageName, let sv = supView, let rs = result, let mk = snapKitMaker else { return imageView } imageView.image = UIImage(named: imageStr) sv.addSubview(imageView) imageView.snp.makeConstraints { make in mk(make) } rs(imageView) return imageView } }
发表评论