如何在自定义UITableViewCell中使用PureLayout显示图像?

时间:2015-10-22 21:55:13

标签: ios objective-c uitableview autolayout pure-layout

我正在iOS上创建一个图片轮询应用。 Feed将是与发布图像类似的条目实例(无边框)。我使用PureLayout创建了一个自定义UITableViewCell。但是,图像(异步加载)不会显示。

enter image description here

我在图像完成处理程序中尝试了invalidateIntrinsicContentSize之类的内容但是没有用。我是AutoLayout的新手,我正在关注此sample code

以下是我对图像的约束设置和2个顶部标签

- (void) updateConstraints {
    if (!self.didSetupConstraints) {

        self.contentView.bounds = CGRectMake(0.0f, 0.0f, 99999.0f, 99999.0f);

        [NSLayoutConstraint autoSetPriority:UILayoutPriorityRequired forConstraints:^{
            [self.questionLabel autoSetContentCompressionResistancePriorityForAxis:ALAxisVertical];
        }];
        [self.questionLabel autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:kLabelVerticalInsets];
        [self.questionLabel autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:kLabelHorizontalInsets];
        [self.questionLabel autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:kLabelHorizontalInsets];


        [self.nameLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.questionLabel withOffset:kLabelVerticalInsets];

        [NSLayoutConstraint autoSetPriority:UILayoutPriorityRequired forConstraints:^{
            [self.nameLabel autoSetContentCompressionResistancePriorityForAxis:ALAxisVertical];
        }];
        [self.nameLabel autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:kLabelHorizontalInsets];
        [self.nameLabel autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:kLabelHorizontalInsets];
        [self.nameLabel autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:kLabelVerticalInsets];



        [NSLayoutConstraint autoSetPriority:UILayoutPriorityRequired forConstraints:^{
            [self.mainImageView autoSetContentCompressionResistancePriorityForAxis:ALAxisVertical];
        }];

        [self.mainImageView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.nameLabel withOffset:kLabelVerticalInsets];

        [self.mainImageView autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:0];
        [self.mainImageView autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:0];
        [self.mainImageView autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:0];


        self.didSetupConstraints = YES;
    }

    [super updateConstraints];
} 

0 个答案:

没有答案