UITableViewCell in ios7 now has gaps on left and right

久未见 提交于 2019-12-03 11:55:47

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.

iOS7 added a separatorInset property.

Try adding this to your UITableViewController:

if ([self.tableView respondsToSelector:@selector(separatorInset)]) {
    [self.tableView setSeparatorInset:UIEdgeInsetsZero];
}

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;
}
ShigaSuresh

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

For those using Xamarin/MonoTouch in c#

tableView.SeparatorInset = UIEdgeInsets.Zero;
 override func viewDidLoad() {
    super.viewDidLoad()

    tableView.cellLayoutMarginsFollowReadableWidth = false
 }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!