如何在 Xcode 中设置 UIButton
的背景颜色?
我在布局属性中看到了 Background 和 Image 属性,但我无法在这两个属性中设置任何内容(只能在两者都设置图像而非颜色)。
在属性检查器(Attribute Inspector)
中向下滚动一点,你就可以在视图(view)
部分找到背景(Background)
属性,允许你设置UIButton
的backgroundColor
。
如果你想通过编程方式设置按钮的backgroundColor
。
Objective-C:
self.yourButton.backgroundColor = [UIColor redColor];
Swift 3和Swift 4
self.yourButton.backgroundColor = UIColor.red
Swift 2.3或更低版本
self.yourButton.backgroundColor = UIColor.redColor()