Is it not possible to constrain the base label of a shortcut to match the bottom edge of another view?

I have a custom meter view. And a label that shows the numerical value drawn by the meter. Using AutoLayout constraints, I want to align the baseline

labels with the bottom

view.

When I ctrldrag in between and select the alignment of the bottom parts and then try to use Size Inspector

to adjust it, it won't give me a baseline option for the label (just Top

, bottom

and Center Y

).

Isn't there a way to constrain the base label of the label to match the bottom edge of another view in the storyboard editor?

Can I do this in straightforward code? What would this example look like?

+3


source to share


1 answer


I figured the storyboard editor just didn't want to do this directly. You can do it programmatically with something like this:

NSLayoutConstraint *constraint = [NSLayoutConstraint
    constraintWithItem: self.myView
    attribute: NSLayoutAttributeBottom
    relatedBy: NSLayoutRelationEqual
    toItem: self.myLabel
    attribute: NSLayoutAttributeBaseline
    multiplier: 1
    constant: 0];
[self.myView.superview addConstraint: constraint];

      



To make the storyboard happy, I used a bottom-down constraint and checked the parameter Placeholder remove at build time

.

It is not true that the property secondAttribute

NSLayoutConstraint

is read-only. Otherwise, you could just create an output to the storyboard constraint and just set it to viewDidLoad

.

+1


source







All Articles