-1

i have multiline label, it frame changes according to text length properly. when i get width of label it counts whole label width while I just want first line width. I am using this code to get each line.

NSArray *linesArray = [self getLinesArrayOfStringInLabel:label]; 

when text is too long it works properly but when text is short is breaks line's last word in second line and in label it display single line.

enter image description here

and array is

linesArray = (
    " this is multiline label. I want just first ",
    "line."
)

whats going wrong here??

Sneha
  • 880
  • 9
  • 24
Nisha
  • 33
  • 7

1 Answers1

0

you can get dynamic size of the label using following method

//label is UILabel
CGSize expectedLabelSize = [label.text boundingRectWithSize:self.view.frame.size
                                       options:NSStringDrawingUsesLineFragmentOrigin
                                       attributes:@{NSFontAttributeName:[UIFont fontWithName:@"Font you are using" size:<size of font>]}
                                       context:nil].size;

You can use size for width and height.

Mahendra
  • 8,448
  • 3
  • 33
  • 56