oc 朋友圈发布与朋友圈列表

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/RootTimeYu/article/details/80500734

//设置添加按钮
-(void)setButton
{
    
    float width=(ScreenWidth-40)/3;
    self.btn=[UIButton buttonWithType:UIButtonTypeCustom];
    [self.btn setImage:[UIImage imageNamed:@"btn-addmemory"] forState:UIControlStateNormal];
    self.btn.frame=CGRectMake((self.imgArray.count%3)*width+10, self.imgArray.count/3*width+10, width, width);
    [self.btn addTarget:self action:@selector(ClickBtnImg) forControlEvents:UIControlEventTouchUpInside];
    [self.photoView addSubview:self.btn];

    if (self.imgArray.count==0) {
        self.photoViewHeight.constant=120;
        
    }else{
        self.photoViewHeight.constant=self.imgArray.count/3*width+20;
    }
    
}
//添加按钮,按钮的点击事件
-(void)ClickBtnImg
{
    [[CommonMethods sharedInstance]operatingtableIn:self block:^(UIImage *img)
     {
         [self.imgArray addObject:img];
         [self SetAllImg:img];
         [self setFrame];
     }];
}
//显示所有的img
-(void)SetAllImg:(UIImage *)img
{
    UIImageView *imgView=[[UIImageView alloc]init];
    imgView.frame=self.btn.frame;
    imgView.image=img;
    [self.photoView addSubview:imgView];
}
//添加图片之后按钮移动
-(void)setFrame
{
    float width=(ScreenWidth-40)/3;
    if (self.imgArray.count<3) {
        
        self.photoViewHeight.constant=120;
        
    }else{
        
        self.photoViewHeight.constant=((self.imgArray.count)/3+1)*(width+20);
    }
    self.btn.frame=CGRectMake((self.imgArray.count%3)*width+10, self.imgArray.count/3*width+10, width, width);
   
}

memoryCell *cell=[tableView dequeueReusableCellWithIdentifier:@"memoryCell"];
        memoryDateModel *model=self.dateArray[indexPath.row];
        cell.model=model;
        cell.lab1.text=model.Date;
        cell.lab2.text=model.Date;
        cell.labTitle.text=model.Title;
        cell.labContent.text=model.Number;
        
        
        NSMutableArray *array=[[NSMutableArray alloc]init];
        for (NSDictionary *dic in model.Img)        //img是一个key对应一个数组,从数组里面获取某个key的值   里面在包含N个子数组( {{},{}},{{},{}} )   //每个数组相当于椅子字典
        {
            [array addObject:[dic jh_objectForKey:@"FilePath"]];//把key为ID的值给array.获取图片在服务器的ID
            //            NSLog(@"%@",[dic jh_objectForKey:@"Id"]);
            //            NSLog(@"%@",dic.allKeys);
        }
        NSString *img = [array componentsJoinedByString:@","];//将数组转为字符串用“,”分割
                NSLog(@"%@",img);
        
        UIImageView *imgView1=[[UIImageView alloc]init];
        imgView1.frame=CGRectMake((array.count-1)%3*(ScreenWidth-100)/3+10, (array.count/3)*(ScreenWidth-100)/3, (ScreenWidth-100)/3-10, ((ScreenWidth-100)/3-10));
        imgView1.backgroundColor=[UIColor redColor];
//        imgView.image=img;
        
        for (NSString *str in array) {
            [imgView1 sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",AddressUrl, str]] completed:^(UIImage *image, NSError *error, EMSDImageCacheType cacheType, NSURL *imageURL) {
                
            }];
        }
        
        
        [cell.imgView addSubview:imgView1];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;

最后在进行cell高度适应图片就可以了,类同发布页面

展开阅读全文

没有更多推荐了,返回首页