On Feb 4, 2016, at 2:59 PM, Quincey Morris 
<quinceymor...@rivergatesoftware.com> wrote:
> 
> On Feb 4, 2016, at 13:01 , Steve Christensen <puns...@mac.com 
> <mailto:puns...@mac.com>> 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
{
        CGContextRef            context         = 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

Reply via email to