#import "MainViewController.h"
@interface MainViewController ()
@end
@implementation MainViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
// 创建圆形头像图标
UIImageView *avatar=[[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 300, 300)]autorelease];
// 指定头像。imageNamed:默认图片格式png,其他图片需加后缀(如.jpg),否则检索不到
avatar.center=self.view.center;
avatar.image=[UIImage imageNamed:@"imge2.jpg"];
avatar.backgroundColor=[UIColor blackColor];
// 使用CAShapeLayer将视图改为圆形
CAShapeLayer *shapeLayer=[CAShapeLayer layer];
// 设置形状路径(使用贝塞尔曲线)
UIBezierPath *circlePath=[UIBezierPath bezierPathWithArcCenter:CGPointMake(150, 150) radius:120 startAngle:0 endAngle:M_PI*2 clockwise:YES];
// 为形状图层指定路径
shapeLayer.path=circlePath.CGPath;
// 为当前视图的图层添加圆形遮罩图层
avatar.layer.mask=shapeLayer;
[self.view addSubview:avatar];//avatar:用户头像
}