Reputation: 33
I've set the backgroundColor
via the attributes tab for the view controller in my Storyboard. But I want to show the background color only in the length of the text which is filled into the label, not in the whole possible length.
I can not attach any image, so here is what I would like to have:
Upvotes: 2
Views: 1299
Reputation: 5029
Try the following steps:
UILabel
in the Storyboard.UILabel
to the UIImageView
as this will implicitly give Auto Layout a fixed width for the label.UILabel
and the UIImageView
. This can be achieved by control-dragging from the label to the image view in the Storyboard and selecting "Equal Widths" from the menu that appears.This will cause the UILabel
to dynamically change it's width depending on the width of the text drawn inside it. When you set the backgroundColor
property, it will still fill the label by will only show behind the text. The Equal Widths constraint will make sure that the width of the label never exceeds the width of the image view.
Upvotes: 2