当前位置: 代码迷 >> 综合 >> Masonry 布局tag标签(4343排列)
  详细解决方案

Masonry 布局tag标签(4343排列)

热度:110   发布时间:2023-09-13 20:01:44.0

广告

欢迎大家一起交流 QQ群 139852091 公众号

Masonry 布局tag标签(4343排列)
我是jpg

效果

Masonry 布局tag标签(4343排列)
image.png

demo

//    TagAppDto dto;
//    List<TagAppDto> dtoList = new ArrayList<>();
//    dtos.add(dtoList);
//    int num = 4;
//    for (Tag tag : list) {
//        dto = convert2dto(tag);
//        dtoList.add(dto);
//        if (dtoList.size() == num) {
//            dtoList = new ArrayList<>();
//            dtos.add(dtoList);
//            num = num == 4 ? 3 : 4;
//        }
//    }NSArray *arr1 = @[@"一",@"二二",@"三三三",@"四四四四"];NSArray *arr2 = @[@"五五五五五",@"一",@"二二",];NSArray *arr3 = @[@"一",@"二二",@"三三三",@"四四四四"];NSArray *arr4 = @[@"五五五五五",@"一",@"二二",];NSArray *arr5 = @[@"一",@"二二",@"三三三",@"四四四四"];NSArray *arr12 = @[@"五五五五五",@"一",@"二二",];NSArray *arr6 = @[@"一",@"二二",@"三三三",@"四四四四"];NSArray *arr7 = @[@"五五五五五",@"一",@"二二",];NSArray *arr8 = @[@"一",@"二二",@"三三三",@"四四四四"];NSArray *arr9 = @[@"五五五五五",@"一",@"二二",];NSArray *arr10 = @[@"一",@"二二",@"三三三",@"四四四四"];NSArray *arr11 = @[@"五五五五五"];NSArray *array = @[arr1,arr2,arr3,arr4,arr5,arr12,arr6,arr7,arr8,arr9,arr10,arr11];float buttonW = (SCREEN_WIDTH - 50 - 45) / 4;UIView *listView;for (int i = 0; i < array.count; i++){NSArray *list = array[i];UIView *view = [UIView new];[self.view addSubview:view];[view mas_makeConstraints:^(MASConstraintMaker *make) {if (list.count == 4) {make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 50, 35));make.left.mas_equalTo(self.view.mas_left).offset(25);}else{make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 50 - buttonW, 35));make.left.mas_equalTo(self.view.mas_left).offset(25+buttonW/2+7.5);}if (listView) {make.top.mas_equalTo(listView.mas_bottom).offset(0);}else{make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(40);}}];listView = view;UIButton *listButton;for (NSString *title in list) {UIButton *button = [UIButton new];[button setTitle:title forState:UIControlStateNormal];[button setTitleColor:WHColor_1779ff forState:UIControlStateNormal];[button setTitleColor:WhiteColor forState:UIControlStateSelected];[button setBackgroundImage:[UIImage imageWithColor:WhiteColor] forState:UIControlStateNormal];[button setBackgroundImage:[UIImage imageWithColor:WHColor_1779ff] forState:UIControlStateSelected];if (IPhone6Plus_OR_6sPlus) {button.titleLabel.font = Font(12);}else{button.titleLabel.font = Font(11);}button.layer.cornerRadius = 12;button.layer.masksToBounds = YES;button.layer.borderWidth = 0.5;button.layer.borderColor = WHColor_1779ff.CGColor;[button addTarget:self action:@selector(tagButtonAction:) forControlEvents:UIControlEventTouchUpInside];[view addSubview:button];[button mas_makeConstraints:^(MASConstraintMaker *make) {make.top.mas_equalTo(view.mas_top).offset(0);if (listButton) {make.left.mas_equalTo(listButton.mas_right).offset(15);}else{make.left.mas_equalTo(view.mas_left).offset(0);}make.size.mas_equalTo(CGSizeMake(buttonW, 24));}];listButton = button;}}