Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableViewCell in ios7 now has gaps on left and right

I have a UITableView where, in ios6, my custom cell stretched completely to the left and right sides of the screen. So my square image on the left of the cell was hard up against the phone screen.

However, now in ios7, there is a small gap appearing on the left hand side so the image is now away from the side and slightly overlaps my text within the cell.

This also seems to be happening in other apps I have that I am now viewing in ios7 - all have a gap on the left and perhaps the right as well.

My Custom cell is set to a size of 320 according to Interface Builder - ios 7 hasnt changed this has it?

like image 592
skeg0 Avatar asked Sep 24 '13 13:09

skeg0


4 Answers

iOS7 added a separatorInset property.

Try adding this to your UITableViewController:

if ([self.tableView respondsToSelector:@selector(separatorInset)]) {
    [self.tableView setSeparatorInset:UIEdgeInsetsZero];
}
like image 84
loydbrahn Avatar answered Nov 02 '22 22:11

loydbrahn


I'd prefer to make seperators myself. It feels simpler than struggling with tableview settings.Just set seperators to none, subclass your cells and do this in init.

-(id)initWithCoder:(NSCoder *)aDecoder{
    self = [super initWithCoder:aDecoder];
    if(self){

        UIView *seperator = [[UIView alloc] init];
        [seperator setBackgroundColor:[UIColor blackColor]];
        seperator.frame = CGRectMake(0, self.bounds.size.height-1, self.bounds.size.width, 1);
        [seperator setAutoresizingMask:UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth];
        [self.contentView addSubview:seperator];

    }
    return self;
}
like image 45
Eralp Karaduman Avatar answered Nov 02 '22 23:11

Eralp Karaduman


This is working perfect for me:

-(void)viewDidLayoutSubviews
{
    if ([self.Video_TableVIEW respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.Video_TableVIEW setSeparatorInset:UIEdgeInsetsZero];
    }

    if ([self.Video_TableVIEW respondsToSelector:@selector(setLayoutMargins:)]) {
        [self.Video_TableVIEW setLayoutMargins:UIEdgeInsetsZero];
    }
}

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }

    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}
like image 3
ShigaSuresh Avatar answered Nov 03 '22 00:11

ShigaSuresh


Adding the image to the cell.contentView fixes the problem:

[cell.contentView addSubview:imgView];

This way you don't even have to mind the separatorInset property.

like image 2
Tom Avatar answered Nov 03 '22 00:11

Tom