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?
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.