iOS UIImageView 网络加载图片自适应大小问题

   

#pragma mark - /// //图片部分

    for (int i = 0; i < [_imageArray count]; i++) {

        

        UIImageView * imageV = (UIImageView *)[_imageArray objectAtIndex:i];

        

        

        if (imageV.superview) {

            [imageV removeFromSuperview];

            

        }

        

    }

    

    [_imageArray removeAllObjects];

    

    //自定义图片高度

    

    

    CGFloat showImageH ;

    for (int  i = 0; i < [ymData.showImageArray count]; i++) {

        

        //假定图片的高就是80ShowImage_H----kDistance 20 //说说和图片的间隔---#define TableHeader 50


        //自己改的

        showImageH = 80;//(IPHONE_WIDTH - 50)/3;

        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(20 + 5*(i%3) + showImageH*(i%3), TableHeader - 3 + 5 * ((i/3) + 1) + (i/3) *  showImageH + hhhh + kDistance + (ymData.islessLimit?0:30), showImageH, showImageH)];

        imageView.contentMode = UIViewContentModeScaleToFill;

        

//        UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(((screenWidth - 240)/4)*(i%3 + 1) + 80*(i%3), TableHeader + 10 * ((i/3) + 1) + (i/3) *  ShowImage_H + hhhh + kDistance + (ymData.islessLimit?0:30), 80, ShowImage_H)];

        imageView.userInteractionEnabled = YES;

        

        YMTapGestureRecongnizer *tap = [[YMTapGestureRecongnizer alloc] initWithTarget:self action:@selector(tapImageView:)];

        [imageView addGestureRecognizer:tap];

        tap.appendArray = ymData.showImageArray;

        imageView.backgroundColor = [UIColor clearColor];

        imageView.tag = kImageTag + i;

        

        

        

//        image.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",[ymData.showImageArray objectAtIndex:i]]];

        NSString *imgStr = [[ymData.showImageArray objectAtIndex:i] stringByReplacingOccurrencesOfString:@"." withString:@"."];

       

        NSString *imgStr_S = [imgStr stringByReplacingOccurrencesOfString:@"." withString:@"_s."];

        

        NSString *urlStr_S = [NSString stringWithFormat:KimgUrl@"dynamic/%@",imgStr_S];


        NSLog(@"-------朋友圈-    缩略图    -images-----urlStr------%@",urlStr_S);


        

//        UIImage *placeholder = [UIImage imageNamed:@"hstp"];


//        NSString *urlStr = [NSString stringWithFormat:KimgUrl@"dynamic/%@",imgStr];


//        [image setImageURLStr:urlStr placeholder:placeholder];

        __block UIActivityIndicatorView *activityIndicator;

        

        [imageView sd_setImageWithURL:[NSURL URLWithString:urlStr_S] placeholderImage:[UIImage imageNamed:@"mrbg1"] options:SDWebImageProgressiveDownload progress:^(NSInteger receivedSize, NSInteger expectedSize) {

            

            if (!activityIndicator)

            {

                activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];

                activityIndicator.center = imageView.center;

                //把更新UI放到主线程

                dispatch_async(dispatch_get_main_queue(), ^{

                    [imageView addSubview:activityIndicator];

                });

                

                [activityIndicator startAnimating];

            }

            

        } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {

            float a = image.size.width;

            float b = image.size.height;

            NSLog(@"----width--%f----height--%f-------",a,b);

            if ([ymData.showImageArray count] == 1) {

//                [imageView sizeToFit];

             imageView.frame = CGRectMake(20 + 5*(i%3) + showImageH*(i%3), TableHeader - 3 + 5 * ((i/3) + 1) + (i/3) *  showImageH + hhhh + kDistance + (ymData.islessLimit?0:30), a/4, b/4);

//                showImageH = imageView.frame.size.height;

                

                _ShowImage_HH = 150;//600/4;

                

            }else{

                _ShowImage_HH = 80;

            }


            //改变图片的显示方式-----让它不压缩,部分显示

            

            

            

            [activityIndicator stopAnimating];

        }];


//        

//        NSLog(@"------image--- cell ---   尺寸-----%@",NSStringFromCGSize(image.image.size));

//

//        

//        

//        NSURL *url_S = [NSURL URLWithString:urlStr_S];

//        NSData *resultData_S = [NSData dataWithContentsOfURL:url_S];

//        NSLog(@"------cell-图片大小_S--------%lu",(unsigned long)[resultData_S length]);

//        UIImage *img_S = [UIImage imageWithData:resultData_S];

//        NSLog(@"------cell--图片尺寸_S-------%@",NSStringFromCGSize(img_S.size));

//        


        

        

        

        [self.contentView addSubview:imageView];

        [_imageArray addObject:imageView];

        

    }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值