NativeScript: max number of lines on a Label
Asked Answered
C

2

6

If I add textWrap="true" to a Label, text is wrapped over several lines, so far so good.

But I have a very long string and our design only have room for two lines. How do I limit the Label to max two lines?

I'd prefer not to set a height, since that would leave an empty line for texts that could fit on one line?

Cofield answered 10/3, 2017 at 10:8 Comment(0)
C
7

Let's try this:

For Android:

myLabel.android.setMaxLines(2);

For iOS:

myLabel.ios.numberOfLines = 2
Conservatoire answered 10/3, 2017 at 11:2 Comment(1)
Thanks, based your suggest I wrote an {N}-angular-directive for it: gist.github.com/m-abs/ff9da8ed6c01c5c5115da37e4b535a2aCofield
F
0

To add an ellipsis('... ') at the end to indicate that the text is cutoff, implement the directive at the below link. The above one doesn't have any,

https://gist.github.com/EddyVerbruggen/8232252e3a4667e7e20916279f98d3fc

Fridafriday answered 23/3, 2022 at 13:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.