在Swift中使用renderingMode创buildUIImage

在ObjectiveC中我会这样做

UIImage *image = [[UIImage imageNamed:@"myImage.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; 

但在Swift中,我尝试了所有这样的替代方法,但没有成功

 var image : UIImage = UIImage(named:"myImage.png").imageWithRenderingMode(renderingMode: AlwaysOriginal) 

它显示一个错误: 使用未parsing的标识符“AlwaysOriginal”

我怎么做?

这将是正确的语法:


(对于Swift 3.xSwift 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)