Re: auto-layout and rotated UILabels

2016-02-06 Thread Steve Christensen
On Feb 4, 2016, at 2:59 PM, Quincey Morris 
 wrote:
> 
> On Feb 4, 2016, at 13:01 , Steve Christensen  > wrote:
>> 
>> 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
> 
> Can you use a custom class for the embedding view and override its 
> ‘intrinsicContentSize’ property to return the inner view’s height and width 
> reversed?

Quincey: Thanks for a starting point.

I spent this afternoon playing around with it some more. Overriding 
-intrinsicContentSize does result in a correctly sized bounds, but the frame is 
still invalid and the view contents are still drawn incorrectly.

I finally found a simple solution that avoids all the headache of trying to get 
auto layout to play nicely with a transformed UILabel: I don't apply a 
transform to the UILabel. Instead I subclass UILabel and override two of its 
methods: -textRectForBounds:limitedToNumberOfLines: (which 
-intrinsicContentSize calls) and -drawTextInRect:.


- (CGRect) textRectForBounds:(CGRect)bounds 
limitedToNumberOfLines:(NSInteger)numberOfLines
{
CGRect  textRect = [super textRectForBounds:bounds 
limitedToNumberOfLines:numberOfLines];

return CGRectMake(textRect.origin.y, textRect.origin.x, 
textRect.size.height, textRect.size.width);
}

- (void) drawTextInRect:(CGRect)rect
{
CGContextRefcontext = UIGraphicsGetCurrentContext();
CGRect  bounds  = self.bounds;
CGFloat translateX  = bounds.size.width / 2;
CGFloat translateY  = bounds.size.height / 2;
CGAffineTransform   transform   = CGAffineTransformIdentity;

transform = CGAffineTransformTranslate(transform, translateX, 
translateY);
transform = CGAffineTransformRotate(transform, (CGFloat)-M_PI_2);
transform = CGAffineTransformTranslate(transform, -translateX, 
-translateY);

CGContextSaveGState(context);
CGContextConcatCTM(context, transform);

rect = CGRectApplyAffineTransform(rect, transform);
[super drawTextInRect:rect];

CGContextRestoreGState(context);
}

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

auto-layout and rotated UILabels

2016-02-04 Thread Steve Christensen
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
>

(lldb) print (CGRect)[_label bounds]
(CGRect) $0 = (origin = (x = 0, y = 0), size = (width = 141.5, height = 595))

(lldb) po _label.superview
>


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 (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: auto-layout and rotated UILabels

2016-02-04 Thread Quincey Morris
On Feb 4, 2016, at 13:01 , Steve Christensen  wrote:
> 
> 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

Can you use a custom class for the embedding view and override its 
‘intrinsicContentSize’ property to return the inner view’s height and width 
reversed?

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com