ios7 uitableviewcell图像左偏移

时间:2013-09-29 15:55:32

标签: ios uitableview

在iOS 6及更早版本中,uitableviewcell的imageView一直位于左侧,偏移量为0。在iOS 7中虽然已经改变了,现在有15个点的空间。我想像在iOS 6中那样定位imageView。我已经使用AKHighlightableAttributedCell将uitableviewcell子类化,以处理未突出显示的属性文本。所以基于一些搜索我添加了:

- (void) layoutSubviews
{
    [super layoutSubviews];
    // Makes imageView get placed in the corner
    self.imageView.frame = CGRectMake( 0, 0, 80, 80 );
}

问题是其他一切仍然没有重新定位,所以我认为必须有更好的方法来做到这一点。我读过一些人提到使用负偏移来移动所有东西,但我不确定这对于约束是如何工作的,因为它需要适当地扩展每个方向。是否有一个更容易解决的问题,我错过了?谢谢。

1 个答案:

答案 0 :(得分:7)

看来我正在以正确的方式做到这一点。关于字段之间的分隔符的缺失部分是在iOS 7上设置插入。您可以在viewdidload或viewwillload中执行此操作并设置self.tableView.separatorInset = UIEdgeInsetsMake(0,0,0,0);

如果运行iOS 7或更新版本,您将需要添加支票,因为这是我认为的新属性。更好的选择可能是在故事板中设置它,方法是选择表格视图,然后将分隔符插入从默认设置为自定义。

这是重新定位imageView和textLabel的layoutSubviews方法。如果你有一个描述添加它。

- (void) layoutSubviews
{
    [super layoutSubviews];
    // Makes imageView get placed in the corner
    self.imageView.frame = CGRectMake( 0, 0, 80, 80 );

    // Get textlabel frame
    //self.textLabel.backgroundColor = [UIColor blackColor];
    CGRect textlabelFrame = self.textLabel.frame;

    // Figure out new width
    textlabelFrame.size.width = textlabelFrame.size.width + textlabelFrame.origin.x - 90;
    // Change origin to what we want
    textlabelFrame.origin.x = 90;

    // Assign the the new frame to textLabel
    self.textLabel.frame = textlabelFrame;
}