ImageViewをリサイズして角丸にする。

UITableViewに表示する画像をTwitterアプリのユーザーアイコンみたいにするためのTips
まずは画像のサイズ変換。

UIImage *img = [[UIImage alloc] initWithData:data];
float widthPer = 0.5;  // リサイズ後幅の倍率
float heightPer = 0.5;  // リサイズ後高さの倍率
	
CGSize sz = CGSizeMake(img.size.width*widthPer,
					   img.size.height*heightPer);
UIGraphicsBeginImageContext(sz);
[img drawInRect:CGRectMake(0, 0, sz.width, sz.height)];
img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

次は角丸。角丸を「かくまる」って読んでたのは内緒w「かどまる」ですね。

#import <QuartzCore/QuartzCore.h>

cell.imageView.layer.masksToBounds = YES;
cell.imageView.layer.cornerRadius = 5.0f;

最後に、

cell.imageView.image = img;