Open halocq opened 5 years ago
标签个数,长度不确定的,参照了你写的微信demo评论那块
` self.tags = tags; self.buttonsModel = buttonsModel;
if (self.tagViewsArr.count) {
[self.tagViewsArr enumerateObjectsUsingBlock:^(UILabel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
[obj sd_clearAutoLayoutSettings];
obj.hidden = YES;
}];
}
CGFloat margin = 15;
UIView *preViewX = self;
UIView *preViewY = self;
UIView *lastTop = self;
CGFloat preWidth = 15;
for (int i = 0; i < self.tags.count; i++) {
UILabel *label = self.tagViewsArr[i];
label.hidden = NO;
NSDictionary *text;
if ([tags[i] isKindOfClass:[NSString class]]) {
text = @{@"title": [NSString stringWithFormat:@"#%@", tags[i]]};
} else {
text = tags[i];
}
if (preWidth + [self getTextWidth:text[@"title"]] + margin > WIN_WIDTH - 30) {
preViewY = preViewX;
preViewX = self;
} else {
preViewY = preViewY;
}
label.sd_layout
.leftSpaceToView(preViewX, margin)
.topSpaceToView(preViewY, 5)
.heightIs(30);
preViewX = label;
lastTop = label;
preWidth += [self getTextWidth:text[@"title"]];
}
if (tags.count) {
_line.sd_resetLayout
.leftSpaceToView(self, 10)
.topSpaceToView(lastTop, 12)
.widthIs(WIN_WIDTH - 20)
.heightIs([Helper lineHeight:1]);
} else {
_line.sd_resetLayout.heightIs(0);
}
_buttonsView.sd_layout
.topSpaceToView(_line, 0)
.leftSpaceToView(self, 0)
.widthIs(WIN_WIDTH)
.heightIs(65);
[self setupAutoHeightWithBottomView:_buttonsView bottomMargin:0];
`