Question

I am having UITableView in my application, I want to do formatting of it, like change the height of rows in table, change the font and colors of text in cells etc.

Was it helpful?

Solution

It sounds like you should read A Closer Look at Table-View Cells in Apple's Table View Programming Guide for iOS.

Changing the Text Colour and Font

If you're using a standard table view cell, you can customise the text colour and font of its textLabel (or detailLabel) label in the tableView:cellForRowAtIndexPath: data source method:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    /* Cell initialisation code... */
    /* Configure Cell */
    [[cell textLabel] setTextColor:[UIColor grayColor]];
    [[cell textLabel] setFont:[UIFont fontWithName:@"Marker Felt" size:22]];
    return cell;
}

Changing the Height of a Row

If every row is going to be the same height, you should set the rowHeight property of your UITableView:

[tableView setRowHeight:42];

If the rows are going to have variable heights, then you can use the tableView:heightForRowAtIndexPath: delegate method of UITableView:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    CGFloat height = 42;
    if ([indexPath row] == 4) {
        height = 21;
    }
    return height;
}

If you want to completely change the look of your table view cells, you might want to look at Matt Gallagher's Easy custom UITableView drawing article, as suggested by @mfu. However, make sure you know exactly what you're doing if you start going this far—most of the time you will want to stick to Apple's default styles.

OTHER TIPS

Your question is rather general. You can refer to very nice article here to get some basic idea on how you can write custom table view 'easy custom uitableview drawing'

You should look at subclassing UITableViewCell and with that new subclass you can have anything you want inside the cell - other views, buttons, labels, etc.

Apple has many good samples of this. See this for a list of samples.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top