In Obj-C
imageView.contentMode = UIViewContentModeScaleAspectFill;
would set the contentMode.
Why does
imageView.contentMode = UIViewContentModeScaleAspectFill
not work in Swift?
UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage .
Overview. Image views let you efficiently draw any image that can be specified using a UIImage object. For example, you can use the UIImageView class to display the contents of many standard image files, such as JPEG and PNG files.
First you create a UIImage from your image file, then create a UIImageView from that: let imageName = "yourImage. png" let image = UIImage(named: imageName) let imageView = UIImageView(image: image!)
The content mode specifies how the cached bitmap of the view's layer is adjusted when the view's bounds change. This property is often used to implement resizable controls.
Somewhat confusingly, Swift drops the prefix for ObjC enum values:
imageView.contentMode = .scaleAspectFill
This is because Swift already knows what enum type is being used. Alternatively, you can specify the enum too:
imageView.contentMode = UIViewContentMode.scaleAspectFill
Note: In versions of Swift before version 3, "scaleAspectFill" will need to be capitalized.
In swift language we can set content mode of UIImage view like
var newImgThumb : UIImageView newImgThumb = UIImageView(frame:CGRectMake(0, 0, 100, 70)) newImgThumb.contentMode = .ScaleAspectFit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With