Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CGRect instead of self.bounds when drawing text #138

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ata-n
Copy link

@ata-n ata-n commented Apr 11, 2013

Makes subclassing much easier!

Makes subclassing much easier!
@AliSoftware
Copy link
Owner

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?

@ata-n
Copy link
Author

ata-n commented Apr 20, 2013

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];

}

@AliSoftware
Copy link
Owner

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…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants