我正在 iOS 上创建一个图像投票应用程序。提要将是条目的实例,类似于发布的图像(无边框)。我UITableViewCell
使用 PureLayout 创建了一个自定义。但是,图像(异步加载)不显示。
我invalidateIntrinsicContentSize
在图像完成处理程序中尝试过类似的东西,但没有奏效。我是 AutoLayout 的新手,我正在关注这个示例代码
这是我对图像和 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];
}