UITableViewCell imageView导致太多缩进

时间:2012-06-05 17:32:23

标签: ios cocoa-touch uitableview uiimageview

我有一个子类UITableViewCell,我正在设置imageView。我希望将其保持在60x60,因此我在我的子类的frame方法中设置了boundslayoutSubviews

- (void)layoutSubviews {
    [super layoutSubviews];

    self.imageView.bounds = CGRectMake(10,10,60,60);
    self.imageView.frame = CGRectMake(10,10,60,60);
    self.imageView.clipsToBounds = YES;

}//end

这很有效,直到我的图像超出imageView的范围:

enter image description here

因此,我确保将clipsToBounds设置为YES:

enter image description here

但正如你所看到的那样,textLabeldetailTextLabel仍在缩进,即使我不认为它应该是。

如何解决此问题?

2 个答案:

答案 0 :(得分:0)

您可以在textLabel实施中设置-layoutSubviews的位置:

- (void)layoutSubviews {
    [super layoutSubviews];

    self.imageView.bounds = CGRectMake(10,10,60,60);
    self.imageView.frame = CGRectMake(10,10,60,60);
    self.imageView.clipsToBounds = YES;

    CGFloat x = 10.0 + 60.0 + 10.0; // Padding, image width, and padding.

    CGRect frame = self.textLabel.frame;
    frame.origin.x = x;
    self.textLabel.frame = frame;

    frame = self.detailTextLabel.frame;
    frame.origin.x = x;
    self.detailTextLabel.frame = frame;

} //end

您可能想要调整x

的值

希望这有帮助。

答案 1 :(得分:0)

我认为我使用的更好的解决方案是不使用imageView中的构建,而是使用自己的构建。这样做效果更好。

相关问题