I'm building a screen to scan barcodes, and I need to put a translucent screen behind some UILabels
to improve visibility against light backgrounds.
Here's what the screen looks like now:
I'm setting the background color on the UILabel
to get the translucent boxes. I've also created a custom UILabel
subclass to allow me to set some padding between the edge of the UILabel
and the text using this approach.
As you can see in the screen above, the UILabel
doesn't resize correctly to take the padding into account. The "padding" just shifts the text over without changing the width of the label, causing the text to truncate.
Both of these labels will contain text of arbitrary lengths, and I really need the UILabel
to dynamically resize.
What UILabel
method can I override to increase the width of the label and factor in the padding?
sizeToFit
doesn't take into account the padding. I tried overridingsizeToFit
andsizeThatFits
to increase the width of therect
, but it seems to have no effect. – Ocotillo-textRectForBounds:limitedToNumberOfLines:
too – Heap