【发布时间】:2016-07-03 17:19:54
【问题描述】:
我想禁用按下按钮时出现的灰色层。我的按钮有一个特殊的形状,其中一部分是透明的。
未按下:
按下:
我的按钮在 UIView 内。我的 UIView 有一个 clearColor() 背景。我已经尝试为 Normal 和 Highlighted 状态的按钮设置背景图片:
agendaButton.setBackgroundImage(UIImage(), forState: .Normal)
agendaButton.setBackgroundImage(UIImage(), forState: .Highlighted)
我还尝试为两种状态设置相同的图像:
agendaButton.setImage(UIImage(named: "agenda"), forState: .Normal)
agendaButton.setImage(UIImage(named: "agenda"), forState: .Highlighted)
我尝试将图像设置为我的视图的子视图并在顶部放置一个透明按钮:
agendaView.addSubview(UIImageView(image: UIImage(named: "agenda")))
我也尝试设置agendaButton.adjustsImageWhenHighlighted = false
并仅设置.Normale 状态的图像。或者为两种状态设置图像。我还有灰色层。我想知道是不是 UIView 变灰了,但显然不是。我将UIView背景设置为红色,并将按钮变小,我可以看到变灰的显然是按钮而不是UIView。
我尝试以编程方式完成所有操作,并将我的UIButton 类型设置为.Custom 和agendaButton.adjustsImageWhenHighlighted = false 和agendaButton.setImage,然后使用agendaButton.setBackgroundImage,两者都用于.Normal 和.Highlighted 状态。相同的行为。
我想知道是否有办法停用这个灰色层。
问题是按钮的白色部分没有变成灰色,只有透明部分。我尝试了在 SO 上找到的多种解决方案,但找不到任何部分透明按钮。
【问题讨论】:
-
尝试将按钮创建为自定义类型 (
UIButton(type: .Custom)) -
@DantePuglisi 如果我检查情节提要中按钮的类型,它已经是
Custom类型。我应该尝试以编程方式 100% 添加按钮吗? -
我更像是一个“100% 以编程方式”的人,虽然我没有足够的 IB 经验,所以我不知道哪个更好
-
我还尝试使用
agendaButton.adjustsImageWhenHighlighted = false和agendaButton.setImage以编程方式完成所有操作,然后使用agendaButton.setBackgroundImage处理.Normal和.Highlighted状态。相同的行为:( -
您介意用代码更新您的问题吗?