0

我有一个UITableViewCell要设置的子类imageView。我想把它保持在 60x60,所以我在我的子类的方法中设置了frameand :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

在此处输入图像描述

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

在此处输入图像描述

但是正如你所看到的,它仍然在缩进textLabeland detailTextLabel,尽管我认为它不应该是这样。

我该如何解决这个问题?

4

2 回答 2

0

我认为我采用的更好的解决方案是不使用内置,imageView而是使用我自己的。这工作得更好。

于 2012-06-07T15:32:50.137 回答
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

希望这可以帮助。

于 2012-06-06T09:43:27.883 回答