我的应用程序中有几个使用图片的按钮。
对于 Interface Builder 中设置的按钮,我在属性检查器中设置了图像。正如我所希望的,它显示没有色调。我检查了用于在界面生成器中设置图像的方法是 UIButton setImage:forState:
现在,如果我尝试在 UITableViewController
中的 cellForRowAtIndexPath
中设置按钮的图像,图像上会出现色调。
// This puts a tint over the button
customCell.myButton.setImage(buttonImage, forState: .Normal)
作为一种解决方法,我在按钮后面放置了一个 UIImageView
,但是当我为按钮设置动画时,imageView 不会移动,我觉得这很烦人。
我也尝试过这个:
// This results in a blank image on the button
customCell.myButton.imageView?.contentMode = .ScaleAspectFit
customCell.myButton.imageView?.image = buttonImage
如果有人对我做错了什么有建议,我欢迎您的意见。
最佳答案
事实证明imageWithRenderingMode
解决了这个问题。
Creates and returns a new image object with the specified rendering mode. A new image object with the specified rendering mode.
我需要使用AlwaysOriginal
案例:
Always draw the original image, without treating it as a template.
let buttonImage = UIImage(named: buttonImageName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
关于ios - 消除 UITableViewCell 中 UIButton 上的 imageView 色调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35141642/