In objectiveC I would do this
UIImage *image = [[UIImage imageNamed:@"myImage.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
but in Swift I have tried all alternatives like this, without success
var image : UIImage = UIImage(named:"myImage.png").imageWithRenderingMode(renderingMode: AlwaysOriginal)
It shows an error: use of unresolved identifier 'AlwaysOriginal'
How do I do that?
UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage .
The rendering mode controls how UIKit uses color information to display an image. See Providing images for different appearances for creating tintable images with template mode.
that would be the proper syntax:
(for Swift 3.x or Swift 4)
var image: UIImage? = UIImage(named:"myImage")?.withRenderingMode(.alwaysOriginal)
(for Swift 2.x)
var image: UIImage? = UIImage(named:"myImage.png").imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
but you can use this 'shortcut' as well:
var image: UIImage? = UIImage(named:"myImage.png").imageWithRenderingMode(.AlwaysOriginal)
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