Search code examples
uitableviewstaticwidthcell

cell width in a static UITableView


I'm using a UITableViewController with a static table view as options panel in my app. I have a background image which shows a rounded border panel and I would like to fit the static cells inside this image. Unfortunately it looks like it's not possible to set the cells width and that the table tries to get as much space as possible.

How can I fix it?

Thanks a lot

Claus


Solution

  •  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.textLabel.font = [UIFont boldSystemFontOfSize:16];
    
        //cell background image
        UIImageView *backgroundView = [[UIImageView alloc] initWithFrame:CGRectZero];
        cell.backgroundView = backgroundView;
        backgroundView.image = [UIImage imageNamed:@"backgroundimage.png"];
    
        return cell;
    }