Closed sealz closed 7 years ago
After typing this up, I realized that I'm taking care of the custom button being displayed in interface builder by calling prepareForInterfaceBuilder
in my custom button class, but not accounting for when the button is actually drawn on screen.
This ends up solving the problem, although I am not sure if this is the correct step in the drawing lifecycle in which to add the customizations.
override public func layoutSubviews() {
super.layoutSubviews()
self.customize()
}
Hope this is helpful for anyone else that runs into the same problem. :)
@sealz I'm glad you figured it out! It's kind of weird to call customize()
in layoutSubviews()
, since I don't think you should have to. Since you're loading from IB, init?(coder:)
should be sufficient. But maybe awakeFromNib()
is a better place for it? I don't use IB much any more, so I'm a little rusty. Feel free to post back here if you find out anything more. Definitely valuable to have this issue logged in case others have the same problem!
I am attempting to use BonMot to style the
titleLabel
's ofUIButton
s with a custom font and colors.What I expect to happen When setting the
attributedText
value for an@IBDesignable
UIButton
'stitleLabel
with a string styled by BonMot. It should correctly render in interface builder and it should correctly render when running in the simulator.What actually happens
The button is rendered correctly in interface builder, but defaults to the system font color for the default button state in the simulator.
The custom button for this example project is:
What I see in interface builder:
What I see in the simulator:
Setting the
UIButton
's type to "Custom" instead of "System" results in the default white text color being used (or whichever text color is selected in interface builder.)