前端之家收集整理的这篇文章主要介绍了masonry布局使用priorityLow(),纯代码与xib结合,自定义cell中for循环自动创建imageView并且自适应cell的高度 ,前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
masonry布局,纯代码与xib结合,在自定义cell中,for循环动态创建imageView,并且自适应cell的高度。
自适应高度
放眼如今的UI界面设计,可以发现没有任何一个APP可以固定高度,包括文字的换行,图片的数量不确定的种种因素,对于自适应高度已经是基本的要求。
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 100;
}
优先级 priority
if (i == self.imgeArray.count -1) {
make.bottom.equalTo(imageView.superview).offset(0).priorityLow();
}
masonry布局,纯代码与xib结合,在自定义cell中,for循环动态创建imageView
@property (weak,nonatomic) IBOutlet UIView *customImagesView;
- (void)setImgeArray:(NSArray *)imgeArray {
_imgeArray = imgeArray;
CGFloat height = 105;
CGFloat margin = 14;
CGFloat customImagesViewLeft = 107;
// CGFloat width = 158;
CGFloat width = (k_SCREEN_WIDTH - customImagesViewLeft - margin * 2) * 0.5;
for (UIView * subView in self.customImagesView.subviews) {
[subView removeFromSuperview];
}
for (int i = 0; i<self.imgeArray.count; i++) {
UIImageView * imageView = [[UIImageView alloc] init];
[imageView setContentMode:UIViewContentModeScaleAspectFill];
[self.customImagesView addSubview:imageView];
imageView.backgroundColor = [UIColor colorWithRandom];
[imageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(imageView.superview).offset(height * (i / 2) + margin * (i / 2));
make.left.equalTo(imageView.superview).offset(width *(i % 2) + margin * (i % 2));
make.width.offset(width);
make.height.offset(height);
if (i == self.imgeArray.count -1) {
make.bottom.equalTo(imageView.superview).offset(0).priorityLow();
}
}];
}
}
以上是前端之家为你收集整理的masonry布局使用priorityLow(),纯代码与xib结合,自定义cell中for循环自动创建imageView并且自适应cell的高度 全部内容,希望文章能够帮你解决masonry布局使用priorityLow(),纯代码与xib结合,自定义cell中for循环自动创建imageView并且自适应cell的高度 所遇到的程序开发问题。
如果觉得前端之家网站内容还不错,欢迎将前端之家网站推荐给前端开发程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。