如何删除UIButton所选的背景色?

Tom*_*myG 35 iphone objective-c uibutton uikit ios

我正在寻找一个不需要使用图像/ PNG的问题的解决方案.我正在寻找一种方法来删除UIButton它处于选定状态时的蓝色背景颜色,而我却无法在不使用图像的情况下找到方法.在以下情况下,我基本上尝试做类似的事情UITableViewCell:

   cell.selectionStyle = UITableViewCellSelectionStyleNone;
Run Code Online (Sandbox Code Playgroud)

Ruf*_*fus 118

我有同样的问题,我通过将UIButton类型从"System"更改为"Custom"来解决它.当它是"自定义"类型时,蓝色背景颜色不会显示在选定状态.

  • 简单,但它消除了触摸时的漂亮淡入淡出.:( (7认同)
  • @KyleClegg只需更改“突出显示”的颜色,并且在触摸时应淡入该颜色。 (2认同)

sud*_*-rf 18

不幸的是,我现在远离我的测试机器,但有两件事你可以试试.

首先是设置以下属性:

button.adjustsImageWhenHighlighted = NO;
Run Code Online (Sandbox Code Playgroud)

或者在Interface Builder中取消选中"突出显示调整图像".

如果这不像你期望的那样工作,你可以在你绑定它的动作中取消选择按钮,如下所示:

- (IBAction)yourButtonAction:(id)sender {
    [sender setHighlighted:NO];
}
Run Code Online (Sandbox Code Playgroud)

  • 我将“UIButton”的“tintColor”属性设置为“clear”,它在选择时删除了背景蓝色 (3认同)

小智 9

将tintColor的alpha更改为零,如果iOS为5.0或更高版本,则可以正常工作

UIColor *color = [[UIColor alloc] initWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];  
button.tintColor = color;
Run Code Online (Sandbox Code Playgroud)

  • 这使按钮文本闪烁 (3认同)

Aka*_*waj 6

很简单,在中storyBoard,选择您的UIButton并打开attribute inspector。现在向下滚动到View部分,如果需要,可以将Tintproperty 更改为Clear Color或任何特定的颜色。

在此处输入图片说明


Jac*_*ack 5

UIButton 也有custom类型,我们可以将它设置为xcode-

在此处输入图片说明

以编程方式作为-

 let customButton = UIButton(type: .custom) 
  customButton.setTitle("this is Button", for: .normal)
  customButton.setTitleColor(UIColor.blue, for: .normal)
  customButton.frame = CGRect(x: 15, y: 50, width: 300, height: 500)
            self.view.addSubview( customButton)
Run Code Online (Sandbox Code Playgroud)

现在不再有UIButton 的蓝色背景色了