OHAttributedLabel icon indicating copy to clipboard operation
OHAttributedLabel copied to clipboard

CGRect instead of self.bounds when drawing text

Open ata-n opened this issue 12 years ago • 3 comments

Makes subclassing much easier!

ata-n avatar Apr 11 '13 16:04 ata-n

Thanks for your contribution, but this modification of yours will probably break the ability to center the text vertically (self.centerVertically)… Did you test this centering case (and with a partial dirtyRect aRect) to check if it doesn't break anything?

PS : How come would this modification makes subclassing easier?

AliSoftware avatar Apr 15 '13 10:04 AliSoftware

Haven't tested that functionality, Good point! I'll let you know if its ok,

It allows me to do something like this in the subclass:

- (void)drawTextInRect:(CGRect)rect
{
    // Draw stuff around the label or something

    CGRect newRect = rect;

    newRect.size.width = newRect.size.width - 20;
    newRect.origin.y = newRect.origin.y + 5;
    newRect.size.height = newRect.size.height - 10;

    [super drawTextInRect:newRect];

}

ata-n avatar Apr 20 '13 16:04 ata-n

You should not use your newRect that way. If you wish to change the rect in which your text is drawn, there is a method for that, see UILabel documentation and especially the textRectForBounds:limitedToNumberOfLines: methods which is especially expected to be overridden for such purposes.

Let me know if overrinding the official textRectForBounds:limitedToNumberOfLines: method to change your newRect solves your problem. Maybe I should use the rect parameter instead of self.bounds in my code anyway but we definitely need to check the centerVertically=YES case one day…

AliSoftware avatar Oct 02 '13 22:10 AliSoftware