在ObjectiveC中,我会这样做
UIImage *image = [[UIImage imageNamed:@"myImage.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
但是我在Swift中尝试了所有这样的选择,但都没有成功
var image : UIImage = UIImage(named:"myImage.png").imageWithRenderingMode(renderingMode: AlwaysOriginal)
它显示一个错误: 使用未解析的标识符“ AlwaysOriginal”
我怎么做?
那将是正确的语法:
(对于 Swift 3.x 或 Swift 4 )
var image: UIImage? = UIImage(named:"myImage")?.withRenderingMode(.alwaysOriginal)
(对于 Swift 2.x )
var image: UIImage? = UIImage(named:"myImage.png").imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
但您也可以使用此“快捷方式”:
var image: UIImage? = UIImage(named:"myImage.png").imageWithRenderingMode(.AlwaysOriginal)