开发中用到UITableView默认的cell.imageView,有时从接口获取的图片大小不合适,如下图:
需要调整cell.imageview.image的大小
cell.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",_imageArr[indexPath.row]]];
CGSize itemSize = CGSizeMake(35, 35);
UIGraphicsBeginImageContextWithOptions(itemSize,NO,UIScreen.mainScreen.scale);
CGRect imageRect = CGRectMake(0, 0, itemSize.width, itemSize.height);
[cell.imageView.image drawInRect:imageRect];
cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
调整后如下图:
网友评论