Reputation: 171
I am trying to set the font of static table view cells, using Interface Builder. I added all the cells visually using interface builder. Now I want to change the font of the table view cells.
First, I tried selecting the label of each cell and changing it to attributed text, and I set the font. Even the preview is showing the correct font, but the simulator still shows the normal font.
Then I kept it as a plain label, but changed the font from there. Still, the Interface Builder shows the correct font. But the results show otherwise.
So what do I do? It'll be a hassle to create an array, create a bunch of segues, and use the cellForRowAtIndexPath
function. Maybe there's a better way? Thank you.
Upvotes: 0
Views: 813
Reputation: 3790
You should use following method willDisplayCell to set custom fonts of the table cell:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.textLabel.textColor=[UIColor whiteColor];
cell.detailTextLabel.font=[UIFont fontWithName:@"Helvetica" size:16.0];
cell.detailTextLabel.textColor=[UIColor blueColor];
}
because your changes will be lost when the cell is actually displayed using xib file or using cellForRowAtIndexPath
method.
Upvotes: 2