views:

938

answers:

1

I'm using a table cell with subtitle and wanted my text to become a bit larger. Changing the size

cell.textLabel.font = [UIFont boldSystemFontOfSize:30];

and cell height heightForRowAtIndexPath to 80 I run into the problem that the textLabel is half hidden by detailTextLabel. I'm surprised this is not handled properly. I have tried to change bounds of the labels but it had no effect. How do I set the "position", "content rect" or whatever to have a large textLabel and a small detailTextLabel?

A: 

I believe this is fixed in later versions of iOS. However if you do want to provide custom layouts for 'subtitle' or other styled cells (in order to take advantage of some of the layout features such as positioning images/accessories, etc.) you can do so fairly easily by subclassing them. In the subclass init the superclass with the required style and override layoutSubviews as follows:

- (void)layoutSubviews
{
    [super layoutSubviews];
    // Set the content view frame
    CGRect cvFrame = self.contentView.frame;
    cvFrame.origin.y = 0;
    cvFrame.size.height = 80;
    self.contentView.frame = cvFrame;
    // Set the text label position
    CGRect tlFrame = self.textLabel.frame;
    tlFrame.origin.y = 2;
    self.textLabel.frame = tlFrame;
    // Set the detail label position
    CGRect dtlFrame = self.detailTextLabel.frame;
    dtlFrame.origin.y = 2 + tlFrame.size.height + 2;
    self.detailTextLabel.frame = dtlFrame;
}

This way you can use the frame values that have been set in [super layoutSubviews] and set your own. If you are adding more views to the cell you can set their position here too.

jhabbott