I had the same problem. Not showing on the phone, but perfect on Storyboard and UI debugger. It was also working when I was putting the project "Opens with Xcode 7" instead of 8 but wasn't a satisfying solution. So I digged and found out the problem. The trouble was with a class looking like this :
@IBDesignable public class MyButton: UIButton {
@IBInspectable var styleName: String = "" {
didSet {
switch styleName {
case "RoundedLight":
tintColor = UIColor.lightPinkColor()
layer.borderColor = UIColor.whiteColor().CGColor
layer.borderWidth = 1
layer.masksToBounds = true
default:
break
}
}
}
override public func layoutSubviews() {
super.layoutSubviews()
switch styleName {
case "RoundedLight":
layer.cornerRadius = frame.height / 2
default:
break
}
}
}
I changed it to this and it works now :
@IBDesignable public class MyButton: UIButton {
@IBInspectable var styleName: String = "" {
didSet {
layoutIfNeeded()
}
}
override public func layoutSubviews() {
super.layoutSubviews()
switch styleName {
case "RoundedLight":
tintColor = UIColor.lightPinkColor()
layer.borderColor = UIColor.whiteColor().CGColor
layer.borderWidth = 1
layer.cornerRadius = frame.height / 2
layer.masksToBounds = true
default:
break
}
}
}
Note that none of the above worked for me, and I mean :
- Calling
layoutIfNeeded
in the layoutSubviews()
- Calling
layoutIfNeeded
in the awakeFromNib
of my button (or my cell containing the button)
- Calling
layoutIfNeeded
in the layoutSubview
of my cell
- Calling
contentView.layoutIfNeeded()
in the awakeFromNib
of my cell
- Calling
view.layoutIfNeeded()
in my view controller