Re: UIStackView full of labels doesn't add up
Re: UIStackView full of labels doesn't add up
- Subject: Re: UIStackView full of labels doesn't add up
- From: Roland King <email@hidden>
- Date: Mon, 21 Mar 2016 11:47:31 +0800
> On 20 Mar 2016, at 22:52, Ken Thomases <email@hidden> wrote:
>
> On Mar 20, 2016, at 7:57 AM, Roland King <email@hidden> wrote:
>>
>> I have a UIStackView, vertical, set to ‘fill equally’ with a number of UILabels in it. The stackview in this instance happens to be 300pts high. If I put 1 UILabel in it, the UILabel is 300pts high. This is what I would expect.
>>
>> If I put two in it, the stackview sets them both 160pts high (total 320), three, they’re 113pts high (total 330) , four, 90pts high (total 360). None of those add up to 300 so the labels are not properly spaced out and don’t line up correctly with other groups of views which are next to them.
>
> What are you using to measure the label heights? Are you looking at the frame or the alignment rect (i.e. applying -alignmentRectForFrame: to the frame)? Anything using auto layout, such as UIStackView, will use the alignment rect. The alignment rect may very well be inset from the frame so that if you (or UIStackView) makes two labels abut according to their alignment rects, their frames may actually overlap.
>
> Also, have you set the stack view's baselineRelativeArrangement or spacing properties?
>
> Regards,
> Ken
>
Using the frame - however if I change IB to show alignment rect, I get the same dimensions, although that may be IB lying to me. I’ve tried setting the layout margins on the UILabels to zero, that didn’t make a difference. There’s no baselineRelativeArrangement or spacing properties set on the stack view either. I would expect if it were alignment rect then the frames would overlap (they do) but I would also expect the frames all to be offset by the same amount from the top edge. What actually happens is the topmost label’s top edge is flush to the top edge of the stack, the bottom label’s bottom edge is flush to the bottom edge of the stack. Since they are all a little too high, that means the top label’s text is about 8 pixels low, the bottom one’s is 8px high and the label in the middle is correct. When you add enough of them, the effect is disturbingly obvious.
I’ll stick with the label in a view code which seems to work and I can even then align either the label center or baseline to the center of the view, haven’t decided which looks nicer yet.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden