Reputation: 2014
So I'm trying to use autolayout for cell content view to get the proper layout. So my problem is that I have a UILabel
that changes its size with respect to its text and I also have a UIView
as a background view for this label with rounded corners. So my question is, how to force this UIView's
width to be 10 points wider than the UILabel
. I managed to make it the same width but how can I force it always to be a certain length wider?
Thank you in advance!
Upvotes: 2
Views: 1667
Reputation: 1937
An autolayout constraint is nothing but an equation of the form
attribute1 == multiplier × attribute2 + constant
Note that programatically, you can virtually set any constraint on your views. The interface builder is however a bit limited given that you can relate only certain pairs of (attribute1,attribute2)
an as you have noticed you may not be able to provide constant
.
Upvotes: 0
Reputation: 6383
NSLayoutConstraint *widthConstraint = [NSLayoutConstraint constraintWithItem:yourLabel
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:yourLabel.superview
attribute:NSLayoutAttributeWidth
multiplier:1.0
constant:10]; // <-- this
[yourLabel.superview addConstraint:widthConstraint];
Upvotes: 4