Re: NSAttributedString boundingRectWithSize vs. paragraph margins
Re: NSAttributedString boundingRectWithSize vs. paragraph margins
- Subject: Re: NSAttributedString boundingRectWithSize vs. paragraph margins
- From: Matt Neuburg <email@hidden>
- Date: Thu, 24 Jan 2013 06:48:58 -0800
UILabel sizeToFit shows the same problem. If I start with a tall UILabel and set its attributedText to my string, and then tell the label to sizeToFit, the label gets narrower and the text no longer fits. This is because the sizeToFit algorithm is ignoring the margins (in fact it is probably using boundingRectWithSize behind the scenes). m.
> On Jan 23, 2013, at 11:01 PM, Kyle Sluder <email@hidden> wrote:
>
>>> It may be that the height is right despite the narrowed width, but since the narrowed width is unexpected, it would be nice to be assured of this. m.
>>
>> Why is the narrowed width unexpected? You told the text system to use 20pt margins on each side of a 100pt text container.
>
> I expect this method to tell me the size of a rectangle (e.g. a bitmap context) such that if I draw my attributed string into that rectangle, it will all fit. When I say "all" I mean "all", including the margins.
>
> Instead, this method is telling me the size of a tight rectangle around the black marks the letters make. That is not at all the same thing.
>
> It is easy to see the difference. Let's say I say this:
>
> CGRect r = [as boundingRectWithSize:CGSizeMake(100,10000) options:NSStringDrawingUsesLineFragmentOrigin context:nil];
>
> And let's say the answer is {51.8027, 465}. Well, if I try to draw my string into a rect of size {51.8027, 465}, it won't fit. That's because the 20pt margins will be applied within those bounds, so my text will be trying to fit in an 11pt space, and will be much longer than 465pt high.
>
> Therefore I believe this is a bug. I asked for the bounding rect of my string, but the system gave me the bounding rect of a *different* string, a string that has no margins. m.
--
matt neuburg, phd = email@hidden, http://www.apeth.net/matt/
pantes anthropoi tou eidenai oregontai phusei
Programming iOS 5! http://shop.oreilly.com/product/0636920023562.do
RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
TidBITS, Mac news and reviews since 1990, http://www.tidbits.com
_______________________________________________
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