How to check if UILabel is truncated?

前端 未结 20 2758
不知归路
不知归路 2020-11-28 02:53

I have a UILabel that can be varying lengths depending on whether or not my app is running in portrait or landscape mode on an iPhone or iPad. When the text is

20条回答
  •  我在风中等你
    2020-11-28 03:13

    Wouldnt it be easy to set the title attribute for the label , setting this will display full label when hovered.

    you can calculate the length of the label and div width (convert to length - jQuery / Javascript - How do I convert a pixel value (20px) to a number value (20)).

    set jquery to set title if length is greater than the div width.

    var divlen = parseInt(jQuery("#yourdivid").width,10);
    var lablen =jQuery("#yourlabelid").text().length;
    if(lablen < divlen){
    jQuery("#yourlabelid").attr("title",jQuery("#yourlabelid").text());
    }
    

提交回复
热议问题