Skip to content

Instantly share code, notes, and snippets.

@Gurpartap
Created January 17, 2012 08:56
Show Gist options
  • Save Gurpartap/1625737 to your computer and use it in GitHub Desktop.
Save Gurpartap/1625737 to your computer and use it in GitHub Desktop.
Custom UILabel in cell
UILabel *messageTextLabel = [[UILabel alloc] init];
messageTextLabel.text = @"Hello World";
CGSize maximumSize = cell.contentView.frame.size; // adjust this.
UIFont *font = [UIFont systemFontOfSize:14];
CGSize stringSize = [messageTextLabel.text sizeWithFont:font
constrainedToSize:maximumSize
lineBreakMode:messageTextLabel.lineBreakMode];
messageTextLabel.frame = CGRectMake(
messageTextLabel.frame.origin.x,
messageTextLabel.frame.origin.y,
maximumSize.width,
MIN(maximumSize.height, stringSize.height)
);
[cell.contentView addSubview:messageTextLabel];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment