Created
January 17, 2012 08:56
-
-
Save Gurpartap/1625737 to your computer and use it in GitHub Desktop.
Custom UILabel in cell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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