I have created a series of 'translucent' UI elements using @IBDesignable
where I set the background colour to white with a low, partial alpha.
This works for UIView
but for UIButton
the background stays clear and the text colour, while correctly appears as white at runtime, shows as the default blue in Xcode (IB).
What am I doing wrong here? If it works for UIView
I do not understand why the same code does not work for UIButton
.
import UIKit
@IBDesignable
class TranslucentButton: UIButton {
override func drawRect(rect: CGRect) {
backgroundColor = UIColor(red: 1, green: 1, blue: 1, alpha: 0.1)
setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
layer.cornerRadius = 4
layer.masksToBounds = true
layer.borderColor = UIColor.whiteColor().CGColor
layer.borderWidth = 1
}
}
@IBDesignable
class TransulucentUIView: UIView {
override func drawRect(rect: CGRect) {
backgroundColor = UIColor(red: 1, green: 1, blue: 1, alpha: 0.1)
layer.cornerRadius = 4
layer.masksToBounds = true
layer.borderColor = UIColor.whiteColor().CGColor
layer.borderWidth = 1
}
}