Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/100.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何删除选定的背景色?_Ios_Objective C_Iphone_Uibutton_Uikit - Fatal编程技术网

Ios 如何删除选定的背景色?

Ios 如何删除选定的背景色?,ios,objective-c,iphone,uibutton,uikit,Ios,Objective C,Iphone,Uibutton,Uikit,我正在寻找不需要使用图像/PNG的解决方案。我正在寻找一种方法来删除ui按钮处于选中状态时的蓝色背景色,我就是找不到一种不使用图像的方法。对于UITableViewCell,我基本上是在尝试这样做: cell.selectionStyle = UITableViewCellSelectionStyleNone; 使用 不幸的是,我现在不在我的测试机旁,但有两件事你可以试试 首先是设置以下属性: button.adjustsImageWhenHighlighted = NO; 或者取消选

我正在寻找不需要使用图像/PNG的解决方案。我正在寻找一种方法来删除
ui按钮处于选中状态时的蓝色背景色,我就是找不到一种不使用图像的方法。对于
UITableViewCell
,我基本上是在尝试这样做:

   cell.selectionStyle = UITableViewCellSelectionStyleNone;
使用


不幸的是,我现在不在我的测试机旁,但有两件事你可以试试

首先是设置以下属性:

button.adjustsImageWhenHighlighted = NO;
或者取消选中界面生成器中的“高光调整图像”

如果这不符合您的预期,您可以取消选择将其绑定到的操作中的按钮,如下所示:

- (IBAction)yourButtonAction:(id)sender {
    [sender setHighlighted:NO];
}

不确定这是不是最好的方法。但是,您可以在实际按钮的顶部有一个不可见的按钮或视图,然后识别单击顶部按钮/视图的时间。

如果iOS为5.0或更高版本,请将tintColor的alpha更改为零

UIColor *color = [[UIColor alloc] initWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];  
button.tintColor = color;

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

Swift版本

extension UIButton {
    override public var highlighted: Bool {
        didSet {
            // clear background color when selected
            self.layer.backgroundColor = .None
        }
    }
}

它为我做的是在突出显示状态下更改button.tintColor。这是swift 3,iOS 10

override public var isHighlighted: Bool {
    didSet {
        self.tintColor = UIColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 1.0)
    }
}
也可以在界面生成器中执行相同的操作


ui按钮还带有
自定义类型,我们可以在
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)

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

非常简单,在
情节提要
中,选择您的
UIButton
并打开
属性检查器
。现在向下滚动到
View
部分,并将
Tint
属性更改为
Clear Color
或任何特定颜色(如果需要)


不是对OP问题的直接回答,但要在
ui按钮
子类中删除此颜色,可以执行以下操作:

override func layoutSubviews() {
    tintColor = .clear
    super.layoutSubviews()
}

在IB中将UIButton类型更改为Custom对我很有用。

这样做了,但不是以一种干净的方式进行的-当我单击时,您仍会在短时间内看到蓝色。我希望找到一个能完全消除这种情况的解决方案。那你为什么不创建自己的
UIControl
?没那么难。然后你可以随心所欲地定制它。仍然很好,ios:9.3,只需
button.adjustsImageWhenHighlighted=NO
就足够了。我将
tintColor
ui按钮的属性设置为
clear
它在选择时删除了背景蓝色。这会使按钮文本闪烁增加混合的CPU使用。您可以在Swift 5If中设置
button.tintColor=.clear
tintColor
是清晰的,然后一旦按钮的
状态设置为
选中
,则不会显示任何文本。简单,但它会消除触摸时的淡入淡出效果:(@KyleClegg只需更改突出显示的颜色,触摸时就会褪色。哇,刚刚在自定义按钮上尝试了所有这些答案,但没有一个成功。
override func layoutSubviews() {
    tintColor = .clear
    super.layoutSubviews()
}