Set alpha of background of UIButton but not the title
This works for me:
self.myButton.backgroundColor = [UIColor clearColor];
or if you don't want to have it completely clear, but still with transparency you can use:
self.myButton.backgroundColor = [UIColor colorWithRed:200.0/255.0 green:200.0/255.0 blue:200.0/255.0 alpha:0.5];
The second example would give you gray color with alpha 0.5.
SWIFT 4 Update
myButton.backgroundColor = .clear
OR
myButton.backgroundColor = UIColor(red: 200.0/255.0, green: 200.0/255.0, blue: 200.0/255.0, alpha:0.5)
In Swift:
import UIKitclass SignInUpMenuTableViewControllerBigButton: UIButton { required init(coder aDecoder: NSCoder) { super.init(coder: aDecoder) self.applyCustomDesign() } func applyCustomDesign() { // We set the background color of the UIButton. self.clearHighlighted() } override var highlighted: Bool { didSet { if highlighted { self.highlightBtn() } else { self.clearHighlighted() } } } func highlightBtn() { self.backgroundColor = UIColor.whiteColor().colorWithAlphaComponent(0.0) } func clearHighlighted() { self.backgroundColor = UIColor.whiteColor().colorWithAlphaComponent(0.05) }}
Swift 4.2
import UIKitclass SignInUpMenuTableViewControllerBigButton: UIButton { required init(coder aDecoder: NSCoder) { super.init(coder: aDecoder) self.applyCustomDesign() } func applyCustomDesign() { // We set the background color of the UIButton. self.clearHighlighted() } override var highlighted: Bool { didSet { if highlighted { self.highlightBtn() } else { self.clearHighlighted() } } } func highlightBtn() { self.backgroundColor = UIColor.whiteColor().withAlphaComponent(0.0) } func clearHighlighted() { self.backgroundColor = UIColor.whiteColor().withAlphaComponent(0.05) }}