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

'numberOfLines' property is ignored #34

Closed
huntrax11 opened this issue Aug 11, 2011 · 6 comments
Closed

'numberOfLines' property is ignored #34

huntrax11 opened this issue Aug 11, 2011 · 6 comments

Comments

@huntrax11
Copy link

In UILabel there is a property named numberOfLine.
If this property set, Label text is automatically truncated if above specified line limit. (blah blah ...)
It'll be more helpful if numberOfLines property also work with OHAttributedLabel-
Can you handle this?
Thanks -

@AliSoftware
Copy link
Owner

I know that this property is ignored, but the problem is that would be very painful to handle, considering the way CoreText works.

Actually, until now the text framing is done using a CTFrameSetter which does everything needed for the text framing for us. In one call, it returns CTLines positionned right according to word wrapping, the font and size of the glyphs, etc.

If we want to handle the numberOfLines limitation, we will instead need to manage the framing of the text manually, CTLine by CTLine, and thus managing when words are wrapped to the next line and how to position each line compared to the previous one, given its height even if it is composed of glyphs of different font size...
This will then be a lot of code (and lot of risks of side-effects) for a such minor feature, whereas CTFrameSetter does this for us if we don't care about numberOfLines.

The thing is I won't have time neither to develop & code nor to intensively test (as this would require quite some tests for some special use cases I think about !) this manual implementation of the text framing, I don't plan to implement this in a near future myself. But feel free to try to implement it yourself in a fork, test it, and send me a pull request then so I can integrate it.

@yashesh
Copy link

yashesh commented Feb 27, 2012

I had same problem so, I had add two line to code and it's working fine.

lableName.numberOfLines = 0;
lableName.lineBreakMode = UILineBreakModeWordWrap;

Thanx :)

lazarev added a commit to lazarev/OHAttributedLabel that referenced this issue Mar 4, 2013
@lazarev
Copy link

lazarev commented Mar 4, 2013

I've fixed it. Thanx to my employer Relonch, Inc. for time in their project.

But it still ignores centerVertically if text can't fit label bounds. For example if only 3 lines can fit and my text needs 4 lines 3 lines would be printed. That's right. But text will be clamped to the top of bounding box even if centerVertically is set to YES. I didn't find clever way to fix it.

@dzenbot
Copy link

dzenbot commented Aug 12, 2013

Even by setting numberOfLines property to 0, the warning is triggered.
Is there anything else to avoid the warnings?

@unoexperto
Copy link

Current CocoaPods version still emits the warning

@AliSoftware
Copy link
Owner

Which is normal because its aim is to warn you that this is still not supported when truncation is used.

You can still use @lazarev 's fork, but I still haven't merged his Pull Request in the master / CP version because it is buggy with the centerVertically property and thus generates a regression. Any fix on this PR is welcome.

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

No branches or pull requests

6 participants