-
Notifications
You must be signed in to change notification settings - Fork 344
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
UILineBreakMode*Truncation modes (leading/trailing "…") and multiline #3
Comments
Hi! This library is a great contribution, thanks so much for putting this together! Gon |
Hi @gon I didn't check in the documentation yet, but contrary to what I stated at the date of registering this issue, this won't probably be as trick as it seems: we need to take care of the truncation in the drawing method, but also in the link detection case. You will probably need to use Or maybe there is a better, easier way to do this (I didn't check the doc fully either, neither did I google about it), especially I wonder what are the values that can be used in the |
I also wonder if it is not in the NSAttributedString itself that we need to define the line truncation mode? |
Greetings! Is this still an issue? I'm trying to use OHAttributedLabel as the view in my navigationItem's titleView (similar to the iPod app's Now Playing, but two lines instead of three). I'm using kCTCenterTextAlignment and kCTLineBreakByTruncatingTail, then I call sizeToFit. Unfortunately, it doesn't resize to the width I expect, and so the ellipsis kicks in. Trying to figure out a sane way around this ... |
Hi @jdandrea Unfortunately this is still an issue and I didn't have time to check it out so far. Thanks! |
Ahh, understood. For now, I ended up increasing the width by 1.0 and ... the text fits! Of course this may be by chance. I'll have to try it with a few different bits of text and see. Where it might get interesting is if the view ends up being too wide. Not sure if the nav bar ratchets that down a bit automagically. |
Actually I think I understood your problem: sizeToFit may resize the label with a smaller width than the original one. |
Oh! That's an interesting thought. In my case, I'm starting with CGRectZero (perhaps that's the problem right there?). Since this is going into the titleView on a nav bar's nav item, I'm not sure what width would work best. Perhaps I should start with a max width after all, and see if the nav bar ends up adjusting it to fit. Thanks for the tip! I'll check back with results. |
I didn't even have to do that. I just kept the width one greater than it already was, and the nav bar does the rest. |
Hi My latest commit includes flooring the values returned by |
Thanks! That worked. :) |
Wooops closed the issue by mistake (your sizeToFit issue is solved/closed by my last comment... but this issue #3 itself is related to "UILineBreakMode*Truncation" and should not be closed). Reopening. |
Is there a workaround for this? I'd like to prevent the warning from showing up in my log - any line break mode is fine for me, as long as there's no warning in my debug console. :) |
@joshuatbrown Errr I don't understand your question… if any line break mode is fine for you, why don't you choose any line break mode that is not a This is even explained in the warning itself!!
|
My version of OHAttributedLabel does not produce the message with the solution, nor does the solution work. I still get the warning. |
So which version do you use, and which message do you get? The warning in the latest versions always display the part The part "change this property in your XIB file" in the warning is only displayed if your |
I haven't tried this in all cases, but something like this should work for trailing:
|
Thx I'll try that probably this weekend. 👍 To be honest I was kinda "afraid" to implement layout of The bad news is that even if we draw the lines ourselves like with your code, we will have a lot more to manage. So that's a step forward, sure (and I'll probably try and integrate it anyway as it's better than nothing), but unfortunately that does only solve the basic case and tail truncation… (Apple when are you gonna fix this?) |
Hmm, I can't figure out how to set the lineBreakMode property in a storyboard. Can anyone advise? (I'm sure it'll be very obvious!) |
Thank-you @AliSoftware! I'd added the view to the storyboard as a "View", not as a "Label", so those properties were not available. |
I integrated wbyoung's solution into OHAttributedLabel drawTextInRect: method if anyone is interested:
|
Word Wrapping and Truncation is not well managed.
Today the OHAttributed does not support both multiline (numberOfLines>1) and "Truncation" lineBreakMode alltogether : if you choose one of the UILineBreakMode*Truncation mode, only the first line will be displayed.
It is probably easy to add the UILineBreakModeTailTruncation mode support by using the VisibleStringRange information (I just don't have time to add this right now)
The text was updated successfully, but these errors were encountered: