I'm desperately trying to constrain the first baselines of a UILabel
and a UITextView
in Interface Builder. From my understanding this should be quite easy by simply adding the following constraint (Pseudo-Code):
label.firstBaseline = textView.firstBaseline
However, depending on the other constraints and some view settings I get really awkward results as shown in the following screenshots.
1st Case: Disable scrolling & Align the top edges
This is only for showing the general view setup. I have disabled scrolling for the textView
to avoid ambiguity. (Otherwise the textView
cannot calculate its own height from its containing text.)
2nd Case: Disable scrolling & align the first baselines
Same setup as in the 1st case with the only difference that I have removed the constraint that aligns the top edges of the views and added a constraint that aligns the first baselines of the views instead.
For some reason, the label "takes off" well beyond the bounds of its superview and ends up at a y position of 7764. No idea why.
3rd Case: Constrain height & align the first baselines
Now I have scrolling enabled for the textView
and constrained its height instead.
Obviously the label
's first baseline gets aligned with the textView
s top edge even though the constrained says to align both their first baselines. I read in the Apple docs that the firstBaseline
parameter returns a view's top edge if that view doesn't have a baseline. So it seems that the textView
doesn't have a first baseline in this scenario.
Does a UITextView
in general have no firstBaseline
?
And if so: Why? After all, it's a view that draws text and thus this property should be set.
Any thoughts on this are appreciated.