M&M
Posts: 0
Joined: Tue Nov 11, 2014 6:59 am

Check if a label takes more than 2 line

hi,

I want to check if a label is taking more than 2 lines. Because if it does then I want to only show part of the label with a ... ( dot dot dot) in the end

For example if the label spans 3 lines

code
This is a very long label
It has lots of text and
I don't want to show so
much information
/code

I want to reduce it to
code
This is a very long label
It has lots of text...
/code
Then display the complete information in a popup if the user clicks on the label.

M&M
Posts: 0
Joined: Tue Nov 11, 2014 6:59 am

Check if a label takes more than 2 line

I don't want to use substring or mid function straightaway because I want to show the dot dot dot only if the label takes more than 2 lines. I cannot strictly calculate the number of characters in the string because they won't all be same width. Uppercase / lowercase characters take up different width depending on font

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Check if a label takes more than 2 line

Hi M&M,

You can use "text-overflow" for single line..
More details: http://www.w3schools.com/cssref/css3_....

Also you can write your own custom script to define characters that will fit your 2-line label.

For this goal you can:

  1. Iteratly add new portion of text(start from 1 character text and up to all text charactes.) and set this text inside label.

  2. Every iteration - get height of this label.

  3. If height - more than some value(2 lines) - this string not fit this label. So you can get previous value.

    Regards.

Return to “Issues”