在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
import UIKit
extension UIImage {
/// 获取网络图片尺寸 /// /// - Parameter url: 网络图片链接 /// - Returns: 图片尺寸size class func getImageSize(_ url: String?) -> CGSize {
guard let urlStr = url else { return CGSize.zero } let tempUrl = URL(string: urlStr)
let imageSourceRef = CGImageSourceCreateWithURL(tempUrl! as CFURL, nil) var width: CGFloat = 0 var height: CGFloat = 0 if let imageSRef = imageSourceRef { let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSRef, 0, nil)
if let imageP = imageProperties { let imageDict = imageP as Dictionary width = imageDict[kCGImagePropertyPixelWidth] as! CGFloat height = imageDict[kCGImagePropertyPixelHeight] as! CGFloat } }
return CGSize(width: width, height: height) } }
|
请发表评论