ios - UIButton 的图像显示模糊?

标签 ios uibutton

我正在尝试将 UIButton 的 图像更改为白色,并在按下时设置背景颜色,最终得到如下结果:

image

我将按钮的图像设置为白色,并像这样设置它的背景颜色:

button.setImage(UIImage(named: "Food_White")?.withRenderingMode(.alwaysOriginal), for: .highlighted)
button.setBackgroundImage(UIImage.imageWithColor(UIColor.gray, size: CGSize(width: 1.0, height: 1.0)), for: .highlighted)

但是当我按下按钮时,白色图像几乎不显示:

button

有人知道如何使图像不那么模糊吗?

最佳答案

您在创建按钮时是否使用默认按钮类型?

尝试使用 .custom 类型而不是默认的 .system 创建按钮

关于ios - UIButton 的图像显示模糊?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44164408/

相关文章:

ios - 使可拖动的 UIButton 正确响应触摸事件

ios - 将 UIView 的大小调整为其 UILabel subview 的大小

用于调整左右立体声 channel 音量的 IOS API

ios - 如何向自定义 UIButton 添加点击操作?

iphone - 用于反转TitleShadowWhenHighlighted 选定状态的UIButton 模拟

iOS - UIPageControl 上的 UIButton 不工作

ios - 创建一组UIButton?

ios - 从 Xcode 分发时分析应用程序版本的错误是什么?

ios - 如何从选项卡内的 View Controller 设置导航栏标题?

ios - 如果 UITextField 和 UITextView 在 Swift 中为空,则禁用 UIButton