iOS 瀑布流的简单用法

来源:互联网 发布:淘宝 中药材 真假 编辑:程序博客网 时间:2024/06/01 08:16
- (void)viewDidLoad{    [super viewDidLoad];    mainScrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];    [self.view addSubview:mainScrollView];    pullArray  = [NSMutableArray array];    [HttpRequset requsetForCurrentPage:1 completon:^(NSDictionary *responseDic) {        NSLog(@"responseDic===%@",responseDic);        NSDictionary * data = responseDic[@"data"];        NSArray * items = data[@"items"];        for (int i = 0; i < items.count; i ++)        {            PullModel * model = [[PullModel alloc] initWithJsonDic:items[i]];            [pullArray addObject:model];        }        [self loadPullView];    }];}-(void)loadPullView{    //一维数组  分别代表左右两列    float colHeight[2] = {0.0,0.0};    for (PullModel * model in pullArray)    {        float height = [model.height floatValue];        float width = [model.width floatValue];      //  NSLog(@"height=====%f,width====%f",height,width);        //重新计算图片宽高        height =height * 150/width;        width = 150;        int index = colHeight[0] <= colHeight[1] ? 0 : 1;        float x = index == 0 ? 0:160;        float y = colHeight[index];        UIImageView * showImageView = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, width, height)];        [showImageView sd_setImageWithURL:[NSURL URLWithString:model.picUrl]];        NSLog(@"model.url==%@",model.picUrl);        [mainScrollView addSubview:showImageView];        colHeight[index] += height + 20;    }    float height = colHeight[0] <= colHeight[1] ? colHeight[1]:colHeight[0];    [mainScrollView setContentSize:CGSizeMake(320, height)];}
0 0
原创粉丝点击