I want to display two words in the uitableviewcell in different fonts similar to the iPhone Address Book. Ex: John Buchanan
Make custom UITableViewCell.
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
}
//Initialize String for Displaying
//NSString *str =
UILabel *lbl;
if ([cell.contentView.subviews count] == 0) {
//Label alloc and init with frame
//lbl = [[UILabel] alloc] initWithFrame:CGRectMake(x,y,width,height)];
//Cofigure Label (text, font, etc.)
lbl.text = str;
//lbl.font = font;
//Add subview
[cell.contentView addSubview:lbl];
//Release
[lbl release];
}
else {
lbl = [cell.contentView.subviews objectAtIndex:0];
lbl.text = str; //Do only set variable value.
}
return cell;
}
Jack Use cell.textLabel.text and cell.textLabel.DetailText.. These are two label in one cell..
Either you should use two UILables, or you can use OHAttributedLabel to draw NSAttributedString..
EDIT:
You can change the UILabel size dynamically using,
CGSize expectedLabelSize = [titleLabel.text sizeWithFont:titleLabel.font];
titleLabel.frame = CGRectMake(xBase, yBase, expectedLabelSize.width, expectedLabelSize.height);
For each of the label create the font and apply to the font property of that label.
+ (UIFont *)fontWithName:(NSString *)fontName size:(CGFloat)fontSize