I am trying to make an offset-ed background to a UILabel in Xcode 9.1.
I have a @IBDesignable
subclass of UIView which contains UILabel. I have next constraints:
I have also overridden intrinsicContentSize
:
override var intrinsicContentSize: CGSize {
get {
var size = self.label.intrinsicContentSize
size.width += offset
size.height *= self.mult
return size
}
}
Now sometimes both if I debug the code and stop on a breakpoint in my overridden intrinsicContentSize
but mostly in Interface Builder I get some ridiculously large values for width like 20,000,010
or something similar. They are pretty random but quite large. Last time Interface Builder complained that you can only make 10,000x10,000 UIView.
In other cases the view intrinsicContentSize.width is 0 and setting placeholder for intrinsicContentSize for my view doesn't help.
If you go to other swift file and come back it can change. Sometimes it show correct value but in most of the times something bogus.
The final layout usually is what I intended, so it works in runtime but I pretty much can't use Interface Builder with this view.
I also tried to init UILabel with empty text or one char text like '.' and frame (0,0,1,1) as I thought that maybe zero frame and nil text provides this behaviour but it seems that doesn't help either.
Do you have any ideas how I can fix this so I can use my OffsetLabel in Interface Builder? Why does this happen?
It seems that after restarting Xcode it works as expected for some time.