zoukankan      html  css  js  c++  java
  • 例如微博中的表情选择排布

    这里获取到所用数据之后,然后再算每一页因该有多少个emojin,然后把每一页有多少个的,然后赋值到数组中,然后进行排版

    #pragma mark - Datas
    - (void)setExpressionDatas:(NSArray *)expressionDatas
    {
        _expressionDatas = expressionDatas;// 修改
        
        // 删除之前的控件, 避免重复创建
        [self.expressionScrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];

        // 设置页数
        NSInteger pageCount = (expressionDatas.count + kEachPageEmotions - 1) / kEachPageEmotions;
        //    self.emotionsPageControl.numberOfPages = pageCount > 1 ? pageCount : 0;
        self.expressionPageControl.numberOfPages = pageCount;
        
        // 创建单页表情容器层
        for (int i = 0; i < pageCount; i ++)
        {
            YSWeiBoExpressionEmojiView *emotionsPageView = [[YSWeiBoExpressionEmojiView alloc] init];
            
            // 计算单页的表情范围
            NSRange range;
            
            //#define kEmotionPageViewMaxCols 7   // 最大列数
            //#define kEmotionPageViewMaxRows 3   // 最大行数
            //#define kEachPageEmotions (kEmotionPageViewMaxCols * kEmotionPageViewMaxRows - 1)        // 边距
            
            range.location = i * kEachPageEmotions;// 20
            // 每次分配后剩余的表情
            NSInteger residueEmotions = expressionDatas.count - range.location;// 减去第一页所剩的个数
            // 单页表情是否填满
            if (residueEmotions >= kEachPageEmotions)
            {
                range.length = kEachPageEmotions;
            }
            else
            {
                range.length = residueEmotions;
            }
            
            // 设置单页表情数
            emotionsPageView.expressionEmojidatas = [expressionDatas subarrayWithRange:range];
            
            [self.expressionScrollView addSubview:emotionsPageView];
        }
        
        // 重新设置子控件 -> 最近表情挤一块
        [self setNeedsLayout];
    }

    获取到使用Frame排布

    - (void)layoutSubviews
    {
        [super layoutSubviews];

        NSInteger emotionsCount = self.expressionEmojidatas.count;
        
        CGFloat emotionButtonW = (self.frame.size.width - 2 *kEmotionPageViewMargin) / kEmotionPageViewMaxCols;
        CGFloat emotionButtonH = (self.frame.size.height - kEmotionPageViewMargin) / kEmotionPageViewMaxRows;
        for (int i = 0; i < emotionsCount; i++)
        {
            YSWeiBoEmotionButton *emotionButton = self.subviews[i];
            emotionButton.backgroundColor = MJRandomColor;
            
            emotionButton.frame = CGRectMake
            (kEmotionPageViewMargin + (i % kEmotionPageViewMaxCols) * emotionButtonW,
             kEmotionPageViewMargin + (i / kEmotionPageViewMaxCols) * emotionButtonH,
                                             emotionButtonW,
                                             emotionButtonH);
        }
    }

  • 相关阅读:
    20135213——信息安全系统设计基础第十周学习总结
    20135213 20135231 信息安全系统设计基础课程第一次实验报告
    20135213——信息安全系统设计基础第九周学习总结
    家庭作业 汇总(更新调整)
    20135213——信息安全系统设计基础第八周期中总结
    家庭作业第三章3.57
    20135213——信息安全系统设计基础第七周学习总结
    20135213——信息安全系统设计基础第六周学习总结
    笔记
    20135213-信息安全系统设计基础第四周学习总结
  • 原文地址:https://www.cnblogs.com/happyEveryData/p/5520888.html
Copyright © 2011-2022 走看看