ios7中的UITableViewCell现在左右有差距

时间:2013-09-24 13:00:45

标签: uitableview ios7 indentation custom-cell

我有一个UITableView,在ios6中,我的自定义单元格完全伸展到屏幕的左右两侧。所以我单元格左侧的方形图像很难对付手机屏幕。

然而,现在在ios7中,左侧出现了一个小间隙,因此图像现在远离侧面,并且在单元格中略微重叠了我的文本。

这似乎也发生在我现在正在ios7中查看的其他应用程序中 - 左侧和右侧都有差距。

根据Interface Builder,我的自定义单元格大小设置为320 - ios 7还没改变它吗?

6 个答案:

答案 0 :(得分:23)

iOS7添加了separatorInset属性。

尝试将此添加到您的UITableViewController

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

答案 1 :(得分:3)

我更喜欢自己制作分隔符。它比使用tableview设置更简单。只需将分隔符设置为none,将单元格子类化并在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;
}

答案 2 :(得分:3)

这对我来说非常合适:

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

答案 3 :(得分:2)

将图像添加到cell.contentView可修复问题:

[cell.contentView addSubview:imgView];

这样您甚至不必考虑separatorInset属性。

答案 4 :(得分:1)

对于那些在c#中使用Xamarin / MonoTouch的人

tableView.SeparatorInset = UIEdgeInsets.Zero;

答案 5 :(得分:0)

 override func viewDidLoad() {
    super.viewDidLoad()

    tableView.cellLayoutMarginsFollowReadableWidth = false
 }
相关问题