1
This commit is contained in:
@@ -45,7 +45,7 @@
|
||||
[self.wanImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.right.left.equalTo(self.containerView);
|
||||
make.top.equalTo(self.vipImageView).offset(70);
|
||||
make.bottom.equalTo(self.containerView);
|
||||
make.bottom.equalTo(self.containerView).offset(-16);
|
||||
}];
|
||||
|
||||
[self.containerView addSubview:self.titleLabel];
|
||||
@@ -74,7 +74,7 @@
|
||||
[g1 mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.equalTo(self.vipImageView);
|
||||
make.top.equalTo(self.desLabel.mas_bottom).offset(18);
|
||||
make.height.mas_equalTo(((113)));
|
||||
make.height.mas_equalTo(((KBFit(122))));
|
||||
}];
|
||||
[g2 mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.right.equalTo(self.vipImageView);
|
||||
@@ -95,12 +95,29 @@
|
||||
make.left.equalTo(g3.mas_right).offset(spacing);
|
||||
make.height.equalTo(g1);
|
||||
make.width.equalTo(g1);
|
||||
// make.bottom.lessThanOrEqualTo(self.containerView).offset(-12);
|
||||
// 让 header 的高度由内部内容决定:最后一个元素贴到底部
|
||||
make.bottom.equalTo(self.containerView).offset(-12);
|
||||
}];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
// 关键:让 header 根据 AutoLayout 自适应高度
|
||||
- (UICollectionViewLayoutAttributes *)preferredLayoutAttributesFittingAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
|
||||
CGFloat targetWidth = layoutAttributes.size.width > 0 ? layoutAttributes.size.width : KB_SCREEN_WIDTH;
|
||||
// 先把自身宽度设为目标宽,便于系统计算高度
|
||||
self.bounds = CGRectMake(0, 0, targetWidth, self.bounds.size.height);
|
||||
[self setNeedsLayout];
|
||||
[self layoutIfNeeded];
|
||||
CGSize fit = [self systemLayoutSizeFittingSize:CGSizeMake(targetWidth, UILayoutFittingCompressedSize.height)
|
||||
withHorizontalFittingPriority:UILayoutPriorityRequired
|
||||
verticalFittingPriority:UILayoutPriorityFittingSizeLevel];
|
||||
CGRect f = layoutAttributes.frame;
|
||||
f.size.height = ceil(fit.height);
|
||||
layoutAttributes.frame = f;
|
||||
return layoutAttributes;
|
||||
}
|
||||
|
||||
#pragma mark - Helpers
|
||||
- (UIView *)gridItemWithImageView:(UIImageView *)iv {
|
||||
// 简单白底圆角卡片承载图标
|
||||
@@ -109,7 +126,7 @@
|
||||
// v.layer.cornerRadius = 12;
|
||||
// v.layer.masksToBounds = YES;
|
||||
[v addSubview:iv];
|
||||
iv.contentMode = UIViewContentModeScaleAspectFill;
|
||||
iv.contentMode = UIViewContentModeScaleAspectFit;
|
||||
[iv mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
// make.center.equalTo(v);
|
||||
// make.width.height.mas_equalTo(40);
|
||||
@@ -193,4 +210,3 @@
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user