Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to change the Font type and size in UITableView?

I want to change Font type and size in UITableView. For example, how would I set it to Tahoma?

like image 331
RAGOpoR Avatar asked Feb 17 '10 15:02

RAGOpoR


2 Answers

cell.textLabel.font = [UIFont fontWithName:@"ArialMT" size:144];

where cell is a UITableViewCell you would return in -tableView:cellForRowAtIndexPath:.

Tahoma is not shipped with iOS by default, nor can you legally copy it without a proper license. But you could provide a custom free font if you don't like Arial, see How to include and use new fonts in iPhone SDK?.

like image 83
kennytm Avatar answered Nov 15 '22 14:11

kennytm


To add to KennyTM's answer:

You can use - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath delegate method of UITableView to configure your UITableViewCell like this:

 - (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 whiteColor];
}

Apple document reads:

A table view sends this message to its delegate just before it uses cell to draw a row, thereby permitting the delegate to customize the cell object before it is displayed. This method gives the delegate a chance to override state-based properties set earlier by the table view, such as selection and background color. After the delegate returns, the table view sets only the alpha and frame properties, and then only when animating rows as they slide in or out.

like image 32
rohan-patel Avatar answered Nov 15 '22 13:11

rohan-patel