One label, two different fonts?
I need to format the text on a label like this:
username: text from this user. This will create additional lines of text to be displayed incl. and so on.
Where "username" is in bold. This will go into the UILabel which is in the custom cell of the table. Is there a way to get this type of layout?
a source to share
For this relatively simple case, you can fake it. You have a label with a bold username and another plain text label in the same position. Insert enough spaces before the plain text to leave room for the username. You can use the UIStringDrawing methods to measure bold text and spaces.
CGSize usernameSize = [theUsername sizeWithFont:theBoldUsernameFont];
CGSize spaceSize = [@" " sizeWithFont:thePlainCommentFont];
NSString *indentedComment = [NSString stringWithFormat:@"%*s%@" , (int)ceil( usernameSize.width / spaceSize.width ) , "" , theComment];
a source to share
You need to use a UIWebView or CoreText to do this kind of rich text layout. WebView has a lot of overhead, but it is the most flexible and you cannot use it efficiently in a UITableView cell. CoreText is low level and not as well documented. You can align the table view and just lay out the table with CSS and HTML in a web view and this is how I do it.
a source to share