ios7 uitableviewcell图像左偏移 [英] ios7 uitableviewcell image left offset

查看:111
本文介绍了ios7 uitableviewcell图像左偏移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In iOS 6 and earlier a uitableviewcell's imageView was positioned all the way over to the left with a 0 offset. In iOS 7 though this has been changed and there is now a 15 point space now. I would like to position the imageView like it is in iOS 6. I'm already subclassing the uitableviewcell with AKHighlightableAttributedCell to deal with attributed text not being highlighted. So based on some searching I added:

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

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

The issue is everything else still doesn't get repositioned and so I'm thinking there must be a better way to do this. I'd read some people mentioning using a negative offset to move everything over but I wasn't sure how this would work with constraints as it needs to scale properly for each orientation. Is there an easier solution to this that I'm missing? Thank you.

推荐答案

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

It appears I was doing it the correct way. The missing piece regarding the divider between fields was setting the inset on iOS 7. You can do this in the viewdidload or viewwillload and set self.tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);

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

You will need to add a check if running iOS 7 or newer as this is a new property I believe. A better option might be setting it in the storyboard by selecting the table view and then setting separator insets from default to custom.

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

Here is the layoutSubviews method that repositions imageView and textLabel. If you have a description add that as well.

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

这篇关于ios7 uitableviewcell图像左偏移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆