auto-layout and rotated UILabels
auto-layout and rotated UILabels
- Subject: auto-layout and rotated UILabels
- From: Steve Christensen <email@hidden>
- Date: Thu, 04 Feb 2016 13:01:54 -0800
Our UI design calls for a UILabel rotated 90° CCW. When I originally started implementing several months ago, I tried going the auto-layout route but ran out of time without a solution, so I went back to manual layout, calculating the size of the label in code then adjusting the frames of the label and adjacent views.
I'm now trying another shot at moving to auto-layout but am still having issues. There doesn't seem to be a lot of information on handling auto-layout and transformed views, but one thing I came across was to try embedding a transformed view in a non-transformed view and then applying peer and superview constraints to the embedding view. I did that, but it looks like the width of the embedding view is set to the text width of the UILabel instead of the text height, which is borne out by the view geometry.
(lldb) po _label
<UILabel: 0x7f959acb1000; frame = (-226.75 226.75; 595 141.5); transform = [6.123233995736766e-17, -1, 1, 6.123233995736766e-17, 0, 0]; text = 'TABLE OF CONTENTS'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7f959acf6ff0>>
(lldb) print (CGRect)[_label bounds]
(CGRect) $0 = (origin = (x = 0, y = 0), size = (width = 141.5, height = 595))
(lldb) po _label.superview
<UIView: 0x7f959d76c2e0; frame = (5 10; 141.5 595); layer = <CALayer: 0x7f959acb0050>>
And here's a screenshot so you can see the current state of things. I set the background on the embedding view to blue and the label's background to red for visibility.
https://www.dropbox.com/s/yb3xem9ii36rris/rotated-uilabel.jpg?dl=0
Ideally there's an all auto-layout solution but I have no clue. At this point I'd be happy if all I had to do was to calculate and set the rotated bounds of the label and then have auto-layout go from there but I'm not even sure what I need to do to make that happen. Does anyone have experience trying to do something like this? The app is running on iOS 8 and later, if that helps.
Thanks,
Steve
_______________________________________________
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