iOSの画像フィレット処理方式の比較
904 ワード
第一の方法:layerに手足を作る
2つ目の方法:(推奨)
:
レイヤーのフィレットを操作しすぎたりレンダリングしたりすると、特にフィレットとシャドウの場合//
self.imageView.layer.cornerRadius = self.imageView.frame.size.width * 0.5;
self.imageView.layer.masksToBounds = YES;
2つ目の方法:(推奨)
:
効率が高く、性能が良い#import "UIImage+extension.h"
@implementation UIImage (extension)
//
- (UIImage *)circleImage
{
// NO
//
UIGraphicsBeginImageContextWithOptions(self.size, NO, 0);
//
CGContextRef ctx = UIGraphicsGetCurrentContext();
//
CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);
CGContextAddEllipseInRect(ctx, rect);
//
CGContextClip(ctx);
//
[self drawInRect:rect];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
return image;
}
@end