在我们玩直播时,我们常常会给主播贴一些标签,比如萌、女神、可爱之类的,平台也会在开发直播app软件时,为我们提供一些标签作为备选,如下图所示,像第一行显示3个标签,第二行显示2个标签,这样的显示设置该如何做出呢?本篇文章就以此为主题,为大家介绍直播软件中的印象标签排列该如何设置。
/*
接收到服务端的数据,自己做处理
*/
//自己封装了一下AFNetworking的网络请求方法
[YBToolClass postNetworkWithUrl:name andParameter:dic success:^(int code, id _Nonnull info, NSString * _Nonnull msg) {
if (code == 0) {
for (NSDictionary *diccc in info) {
if ([[diccc valueForKey:@"ifcheck"] isEqual:@"1"]) {
[selectMutableArray addObject:diccc];
NSArray *list = info;
NSMutableArray *muArr1 = [NSMutableArray array];
NSMutableArray *muArr2 = [NSMutableArray array];据每5个;
NSInteger secionCount;
if (list.count%5 == 0) {
secionCount = list.count/5;
}else{
secionCount = list.count/5+1;
for (int i = 0; i < secionCount; i++) {
NSMutableArray *arr = [NSMutableArray array];
int aaaaa;
if ((i+1)*5>list.count) {
aaaaa = (int)list.count;
}else{
aaaaa = (i+1)*5;
for (int j = i*5; j < aaaaa; j++) {
[arr addObject:list[j]];
[muArr1 addObject:arr];
for (NSArray *arr in muArr1) {
NSMutableArray *threeArr = [NSMutableArray array];
NSMutableArray *twoArr = [NSMutableArray array];
for (int i = 0;i<arr.count;i++) {
if (arr.count>3) {
if (i<3) {
[threeArr addObject:arr[i]];
}else{
[twoArr addObject:arr[i]];}
}else{
[threeArr addObjectsFromArray:arr];
break;
[muArr2 addObject:threeArr];
[muArr2 addObject:twoArr];
infoArray = muArr2;
[impressCollection reloadData];
} fail:^{
//数据处理完成,在uicollectionview的代理方法中铺数据
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return [infoArray[section] count];
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
return infoArray.count;
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
return 15;
}-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
impressCell *cell = (impressCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"impressCELL" forIndexPath:indexPath];
NSDictionary *subDic = infoArray[indexPath.section][indexPath.row];//文字颜色由后台返回16进制
UIColor *color = RGB_COLOR([subDic valueForKey:@"colour"], 1);
cell.contentL.layer.borderWidth = 1;
cell.contentL.layer.borderColor = color.CGColor;
cell.contentL.textColor = color;
cell.contentL.text = [NSString stringWithFormat:@"%@",[subDic valueForKey:@"name"]];
cell.contentL.font = [UIFont systemFontOfSize:15];
BOOL isCons = NO断选中的数组中是否是当前cell 来改变背景颜色
for (NSDictionary *dic in selectMutableArray) {
if ([[subDic valueForKey:@"id"] isEqual:[dic valueForKey:@"id"]])
isCons = YES;
}else{
if (isCons) {
cell.contentL.textColor = [UIColor whiteColor];
cell.contentL.backgroundColor = color;
}else{
cell.contentL.textColor = color;
cell.contentL.backgroundColor = [UIColor clearColor];
return cell;
// 设置页边距。
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
if (section % 2 == 0) {
return UIEdgeInsetsMake(5, 0, 5, 0);
}else{
return UIEdgeInsetsMake(5, _window_width/8, 5, _window_width/8); }
// 设置item大小。计算文字的长度 每个宽度+30
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
CGFloat width;
NSDictionary *subDic = infoArray[indexPath.section][indexPath.row];
width = [[YBToolClass sharedInstance] widthOfString:[NSString stringWithFormat:@"%@",minstr([subDic valueForKey:@"name"])] andFont:[UIFont systemFontOfSize:15] andHeight:30] + 20;
return CGSizeMake(width, 30)
以上代码中,collectionview的flowlayout 我使用的是JYEqualCellSpaceFlowLayout 大家可以在网上自己找一下,更多与开发直播app软件行业相关的资讯和分析会在以后逐渐放出,敬请期待,需要的朋友请关注我。
声明:文章为原创内容,转载请注明链接及作者