UIImageView(图片)

加载图片时候带有中文或特殊符号需要编码

 //先去编码
        NSString *trimPath = [imageUrl stringByRemovingPercentEncoding];
        //拼接数据
        NSString *newUrl = [NSString stringWithFormat:@"%@?imageView2/1/w/%ld/h/%ld/q/85",trimPath,wh,wh];
        //排查?号进行编码
        NSString *finurl = newUrl.mj_urlEncodedString
@property (nonatomic, strong) UIImageView *Img;

- (UIImageView *)Img {
    if (!_Img) {
        UIImageView *imgeView = [[UIImageView alloc] init];
        imgeView.image = [UIImage imageNamed:@"logo_del_pro"];
        imgeView.backgroundColor = [UIColor grayColor];
        imgeView.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(titleImgClick:)];
        [imgeView addGestureRecognizer:tap];
        
        _Img = imgeView;
    }
    return _Img;
}


    [self.Img makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.height.equalTo(@30);
        make.width.equalTo(@30);
    }];

#pragma mark ************** 个人背景被点击
-(void)titleImgClick:(UITapGestureRecognizer *)sender{ 
}

图片适应

    //图片自适应,ImageView会有部分空白
     [_titleImg setContentMode:UIViewContentModeScaleAspectFit];
    
     //去图片中间部分,图片太大的情况
     [_titleImg setContentMode:UIViewContentModeScaleAspectFill];
     _titleImg.clipsToBounds=YES;

  调用
     [self.imvIcon sd_setImageWithURL:[model.image mj_stringEncodeUrl] placeholderImage:kDefaultImage];


计算图片高度


    
    __block CGFloat viewH = 0;
    [_productImg sd_setImageWithURL:imgUrl placeholderImage:[UIImage imageNamed:@"logo_del_pro"] options:SDWebImageLowPriority | SDWebImageRetryFailed completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        
        if (image)
        {
            //判断图片是否有值,避免出现除以零的情况导致崩溃
            viewH = SCREEN_WIDTH * image.size.height / image.size.width;
            
            model.cellHeight = viewH;
           
            if(self.cellHeightBlack)
            {
                self.cellHeightBlack(viewH);
            }

        }
        
    }];
   

清除缓存

   [[SDImageCache sharedImageCache] clearMemory];
    [[SDImageCache sharedImageCache] clearDiskOnCompletion:^{
        [SVProgressHUD showSuccessWithStatus:@"成功"];
    }];
    [[SDImageCache sharedImageCache] deleteOldFilesWithCompletionBlock:^{
         [SVProgressHUD showSuccessWithStatus:@"成功"];
    }];
}

图片在TableView cell 上的点击事件无法监听

Snip20161020_12.png

你可能感兴趣的:(UIImageView(图片))