ios - 消除 UITableViewCell 中 UIButton 上的 imageView 色调

标签 ios swift uitableview uibutton

我的应用程序中有几个使用图片的按钮。

对于 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/

相关文章:

ios - 将 View Controller 的代码移动到演示器如何使 VIPER 中的单元测试更容易?

ios - 从 iPhone 检索 UDID 的注册挑战

ios - Swift PDFKit 分页无法正常工作

swift - 错误 : Could not cast value of type 'NSNull' (0x10e404918) to 'NSString' (0x10d5fac60). (lldb)

swift - 如何在 UITableView SWIFT 中加载更多单元格

javascript - iOS 在 safari 中打开 URL 而不是 Facebook 应用内浏览器 JS、HTML

ios - fatal error : Array index out of range when accessing an array of 10 elements in Swift

ios - Swift:使用 prepareForSegue 将 UIView 容器的高度设置为嵌入式 UITableView 的高度

ios - 获取CoreData一对多关系的索引路径?

ios - 在 DetailViewController 中将 JSON 字符串转换为 NSDictionary