0

I've seen that UILabel intrinsic size doesn't seem to fit exactly the characters it contains.

enter image description here

As you can see in the image, labels have some margin on top and bottom. I can make "Subtitle" get closer to "TITLE" using baseline (title.baseline == subtitle.top), but I would also want to align "TITLE" to its parent top.

I would like to use autolayout constraints if possible.

Ferran Maylinch
  • 10,919
  • 16
  • 85
  • 100

1 Answers1

1

Quick Fix

If your font size is constant for labels, you can try subclassing UILabel and override - (CGSize)intrinsicContentSize

-(CGSize)intrinsicContentSize {
    CGSize intrinsicSize = [super intrinsicContentSize];
    intrinsicSize.height -= 8; // Works good for system font size 17.0
    return intrinsicSize;
}

You might need to play with intrinsicSize.height -= 8; to get desired output.

BangOperator
  • 4,377
  • 2
  • 24
  • 38
  • Thanks. I thought about doing that. It's quite a hack, though... :p --- And I would like it to work for any font, size and characters. I would have to consider all of those and "cook" a magic number. – Ferran Maylinch Dec 03 '15 at 11:57