ImageView size depending remote image size

//Logo Dimensions if let urlLogo = LegionAPI.shared.enterpriseLogoUrl { if let url = URL(string: urlLogo), let imageSource = CGImageSourceCreateWithURL(url as CFURL, nil), let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil) as Dictionary?, let pixelWidth = imageProperties[kCGImagePropertyPixelWidth] as? Int, let pixelHeight = imageProperties[kCGImagePropertyPixelHeight] as? Int { print("the image width is: \(pixelWidth)") print("the image height is: \(pixelHeight)") //Aspect Ratio if pixelWidth != pixelHeight { DispatchQueue.main.async { self.constraintLogoHeight.constant = pixelHeight <= 100 ? CGFloat(pixelHeight) : 100 self.constraintLogoWidth.constant = pixelWidth <= 250 ? CGFloat(pixelWidth) : 250 self.view.layoutIfNeeded() } } } self.imgLogo.setImage(withPath: urlLogo, placeholderImage: #imageLiteral(resourceName: "defaultPlaceholder")) } else { self.imgLogo.image = #imageLiteral(resourceName: "defaultPlaceholder") }
You need to use Constraints outlets

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.