tobihagemann / THLabel

UILabel subclass, which additionally allows shadow blur, inner shadow, stroke text and fill gradient.
https://tobiha.de
Other
665 stars 111 forks source link

Text Clipping #18

Closed superprat closed 10 years ago

superprat commented 10 years ago

Hi,

I'm getting some clipping around the text with the font I'm using ios simulator screen shot 08-sep-2014 3 29 16 pm

I updated the sizetofit method on THLabel but it removes the clipping only on the right hand side

-(void)sizeToFit
{
    [super sizeToFit];
    CGRect frame = self.frame;
    CGRect expandedFrame = CGRectInset(frame, -self.strokeSize * 2, -self.strokeSize *2);
    [self setFrame:expandedFrame];
    [self setNeedsDisplay];
}

ios simulator screen shot 08-sep-2014 3 34 07 pm

The issue is only visible when using sizeToFit. I have faar to many labels to manually set the frames for them. Any suggestions?

superprat commented 10 years ago

whoops, Got it, nvm setTextInsets did the job

tobihagemann commented 10 years ago

I've worked upon your last pull request and came up with a logic for sizeThatFits (because you shouldn't override sizeToFit) that conforms to the available Core Text frame. Could you please test my newest commit if this works for you? There's also a new property called automaticallyAdjustTextInsets which defaults to YES.

superprat commented 10 years ago

I tried it out, It works in some places, but in others it sets the frame too small. The text gets shortened at the end with ...

These same labels were sized properly earlier

tobihagemann commented 10 years ago

Alright thanks for testing. I guess I'll have to do more testing myself. But in your case you're "only" using outside stroke, is that right?

superprat commented 10 years ago

Yup, just strokeColor and strokeSize.

tobihagemann commented 10 years ago

Is there any way you could tell me which (probably custom) font you're using at which font size? I'm not able to reproduce the issue. :/

superprat commented 10 years ago

I'm using the font Damn Noisy kids, available at http://www.dafont.com/damn-noisy-kids.font I don't think it's fontsize dependent. Seeing the issue for all sizes. Strokesize is 2.0

tobihagemann commented 10 years ago

I've commited a fix, but it wasn't even font-related. If it's still producing truncated strings, I'm not sure what the issue is.

superprat commented 10 years ago

Nope, Still producing truncated strings, in more places than before.

tobihagemann commented 10 years ago

I'm so confused. If you could provide a minimal example project and send it to tobias.hagemann@gmail.com, that would be great. It's okay if you don't have the time, but I don't know how/what to test anymore, because I can't reproduce the issue.

superprat commented 10 years ago

The current code is actually crashing on line 435 now EXC_BAD_ACCESS(code=1,address=0x0)

I'll send you a sample project on your email to reproduce the issue

superprat commented 10 years ago

Hey did a little trial and error and I think the string is getting truncated while using AutoLayout. Wasn't able to reproduce the issue in a separate project without it

tobihagemann commented 10 years ago

I've commited a fix for intrinsicContentSize, I guess the sizing behavior is different with Auto Layout. Now I'm rounding up the numbers. But I'm not sure about that crash.

superprat commented 10 years ago

Yup that did it! Everything looks perfect now.

Not sure what that crash is either, not consistently reproducible.

tobihagemann commented 10 years ago

My guess is that I'm using CFRelease too soon on some things, but I thought it's common practice to use CFRelease after using CFCreate. Just went through the code again and couldn't find anything specific. Crashing is bad though, it worries me a bit.

superprat commented 10 years ago

So from what I have observed, the crash is occurring when layoutIfNeeded is being called and the label is being redrawn and the text is nil on line 438. The same issue is not observed on regular UILabels even if the text string is nil.

tobihagemann commented 10 years ago

Whoops! Fixed that with version 1.4.1! Thanks for helping me out! I guess that's it? :D

superprat commented 10 years ago

Yup, looks solid! Thanks for the awesome Label !! :)

tobihagemann commented 10 years ago

Thanks again for testing and giving feedback!