- (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)];
}
iOS 瀑布流的简单用法
最新推荐文章于 2024-02-02 19:26:07 发布