I want to change my UIImageView height/width to match the image i choose from photo album and i found a snippet on here that does that.
-(CGRect)frameForImag
Here is a Swift class that will help return the correct sizing for an image based on a width or height limit that you choose:
class func returnImageSizeForHeightLimit(heightLimit:CGFloat?, orWidthLimit widthLimit:CGFloat?, forImage theImage:UIImage)->CGSize?{
if let myHeightLimit = heightLimit {
let theWidth = (myHeightLimit/theImage.size.height) * theImage.size.width
return CGSizeMake(theWidth, myHeightLimit)
}
if let myWidthLimit = widthLimit {
let theHeight = (myWidthLimit/theImage.size.width) * theImage.size.height
return CGSizeMake(myWidthLimit, theHeight)
}
return nil
}