2013-09-24 89 views
10

我有一个UITableView,在ios6中,我的自定义单元完全拉伸到屏幕的左侧和右侧。所以我手机屏幕左侧的方形图像很难看。ios7中的UITableViewCell现在在左侧和右侧有空白

但是,现在在ios7中,左侧出现一个小间隙,因此图像现在偏离侧边,并且与单元格内的文本略有重叠。

这似乎也发生在我现在正在ios7中查看的其他应用程序中 - 所有的应用程序在左侧都有空白,也许在右侧。

根据界面生成器我的自定义单元格被设置为320的大小 - ios 7没有改变它有吗?

回答

2

添加图像到cell.contentView解决了这个问题:

[cell.contentView addSubview:imgView];

这种方式,你甚至不必介意separatorInset财产。

23

iOS7增加了一个separatorInset属性。

尝试添加以下内容到UITableViewController

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

我曾经尝试这样做没有成功。我的表格视图是由界面构建器制作的,我尝试将代码插入表视图实现中的各个位置,但没有成功(viewdidload,viewwillappear等)。我真的不想进入子类化,如果我可以帮助它,所以我错过了你的方法的东西? – skeg0

+1

如果您正在使用界面构建器,然后选择表格视图,进入属性检查器并在标签为“分隔符插入”的表格视图中找到选择,将下拉列表从默认更改为自定义,然后将左侧值从15更改为0. – loydbrahn

+0

这看起来会改变每个部分的插页的标题,但不会在表格单元格本身内。 – skeg0

1

在C#中使用Xamarin/MonoTouch的那些

tableView.SeparatorInset = UIEdgeInsets.Zero; 
+1

UIEdgeInsetsZero – Jasmeet

+0

我不确定那个评论意味着什么,但我相信我发布的代码是正确的,因为在Xamarin中这些属性被转换为字段,因此它更易于使用。 Documenetation可以在http://docs.go-mono.com/monodoc.ashx?link=T%3aMonoTouch.UIKit.UIEdgeInsets%2f* – Webmonger

+1

我认为上面的评论没有意识到mono是什么。 'tableView.separatorInset = UIEdgeInsetsZero;'为obj-c'tableView.SeparatorInset = UIEdgeInsets.Zero;'为mono! –

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; 
} 
+0

问题是,在视网膜上显示分隔符将是2px厚,而UITableView绘制的将仍然是1px厚。我通过定义区分屏幕分辨率和绘制0.5px或1px行的逻辑来绕过这个限制,但这根本不是未来的保证。 – user3099609

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]; 
    } 
} 
0
override func viewDidLoad() { 
    super.viewDidLoad() 

    tableView.cellLayoutMarginsFollowReadableWidth = false 
}