-1

I have 2 adjacent labels of same width. label1 text takes only one line. Text for label2 is long, objective is to show full text in 2 lines, I am using label.numberOfLines = 2 and adjustsFontSizeToFitWidth = YES;

Now, first line of label2 is not aligned with first line of label1. while labels are still aligned, label2 text is starting with a margin inside label. I wanted label2 text to start from top. please help me with this.

enter image description here

Aakash
  • 69
  • 1
  • Does this answer your question? [Vertically align text to top within a UILabel](https://stackoverflow.com/questions/1054558/vertically-align-text-to-top-within-a-uilabel) – Liftoff Jul 23 '20 at 22:06

1 Answers1

0

Fixed:

CGSize originalSize = [label.text sizeWithAttributes:@{NSFontAttributeName:label.font}];

CGFloat usedScaleFactor = label.frame.size.width / originalSize.width;

CGFloat newFontSize = label.font.pointSize * usedScaleFactor;

label.font = [UIFont fontWithName:@"fontName" size:newFontSize];

This fixed my issue. iOS was calculating label frame with my original text font size while changing my text font due to adjustsFontSizeToFitWidth...

Hope this helps someone who is searching this..

Aakash
  • 69
  • 1