cannot get the right character position of UILabel in TruncateTail mode#6
cannot get the right character position of UILabel in TruncateTail mode#6homekuanyi wants to merge 1 commit intoAliSoftware:masterfrom
Conversation
…bel in Truncate* mode when auto-wrap.
|
It seems strange that when the
So in practice I'm not sure that really fixes the issue (if it seems so, it's probably because you were lucky by testing it with an example text that leads to close-enough results, which won't be the case for text with very-uneven repartition of word lengths) |
|
thanks for answer. Actually i was trying out to find a way to remove the lineBreakMode property of attributedString at the first time, but i failed to do it. i'm not familiar with NSAttributedString, if you know how to remove, tell me please. Since apple doesn't give any api of UILabel's layoutManager, i don't know it's a bug or not. And Truncate mode will not certainly wrap right? There is two lineBreakMode Settings, one is TextContainer, and attributedString the other. There must be only one lineBreakMode works. For my testing, i think UILabel choose TextContainer one, on the other hand our own layoutManager choose attributedString one. So by resetting attributedString's lineBreakMode (or remove it or ignore it, how? ), our own layoutManager will use TextContainer's lineBreakMode. Truncate mode wraps like WordWrap does, so i reset it and everything works ok in my "lucky" testing. I'm very sorry that i cannot give enough testings in this pull request, but i have applied it in my new project, if any things looks strange i will give a feedback. |
|
I think layoutManager uses attributedString to calculate its line number ( if attributedString truncates there is only one line ), then uses TextContainer to do lineBreak, maxNumberOfLine and other display works. |
Hi, thanks for your great work.
I found the layoutManager will not auto-wrap attributedString when lineBreakMode is TruncateTail. So we must reset the lineBreakMode of attributedString.
fix: @selector(characterIndexAtPoint:) return the right index of UILabel in Truncate* mode when auto-wrap.
I hope you would accept it.