2014年4月1日火曜日

[iOS][cocoapods]SDWebImageで解像度を下げずに大きく画像を入れる方法



+ (UIImageView*)setThumbnail:(NSString*)stringURL{
NSURL* imageURL = [NSURL URLWithString:stringURL];
UIImage* tmpImage = [UIImage imageNamed:@"no_image_image"];
UIImageView* iv = [[UIImageView alloc] initWithImage:tmpImage];

[iv setImageWithURL:imageURL placeholderImage:tmpImage];
return iv;

}

こんな感じで入れてあげれば、imageViewに画像が入るんですが、
取得してきた画像を大きくすると画像の解像度が落ちてしまう。

ので、
以下のように修正。

+ (UIImageView*)setThumbnail:(NSString*)stringURL{
NSURL* imageURL = [NSURL URLWithString:stringURL];
UIImage* tmpImage = [UIImage imageNamed:@"no_image_image"];
UIImageView* iv = [[UIImageView alloc] initWithImage:tmpImage];
iv.frame = CGRectMake(0, 0, 510, 360); //追加

[iv setImageWithURL:imageURL placeholderImage:tmpImage];
return iv;
}

予め大きめの画像が入ることを指定しといてあげると、
解像度を下げずに画像をはめてくれます。