If I have an UIImageView with the mode set to center for example how can I change it to something else such as aspect fit with code?
UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage .
An object that manages image data in your app.
Since you have your bgImage assigned and linked as an IBOutlet, there is no need to initialize it as a UIImageView... instead all you need to do is set the image property like bgImage. image = UIImage(named: "afternoon") . After running this code, the image appeared fine since it was already assigned using the outlet.
imageView.contentMode = UIViewContentModeScaleAspectFit;
yourImageView.contentMode = UIViewContentModeScaleAspectFit;
you can set it to any of the following
UIViewContentModeScaleToFill, UIViewContentModeScaleAspectFit, UIViewContentModeScaleAspectFill, UIViewContentModeRedraw, UIViewContentModeCenter, UIViewContentModeTop, UIViewContentModeBottom, UIViewContentModeLeft, UIViewContentModeRight, UIViewContentModeTopLeft, UIViewContentModeTopRight, UIViewContentModeBottomLeft, UIViewContentModeBottomRight
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