ep-yqw
Last Updated: February 25, 2016
·
310
· rebyn
3

UILabel's width to fit its content

Ran into a requirement today that needs a few labels to be content-fit, here's how I did it:

- (void)resizeToContent {
    label.frame = CGRectMake(
         label.frame.origin.x,
         label.frame.origin.y,
         label.intrinsicContentSize.width + {PADDING},
         label.frame.size.height
    );
    // Padding = padding left + padding right
    // Make sure you align your label's content to center
}
Say Thanks
Respond