#import "ViewController.h" #define WIDTH 50 #define PHOTO_HEIGHT 150 @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; CALayer *layer=[CALayer layer]; layer.bounds=CGRectMake(0, 0, PHOTO_HEIGHT, PHOTO_HEIGHT); layer.position=CGPointMake(160, 200); layer.backgroundColor=[UIColor redColor].CGColor; layer.cornerRadius=PHOTO_HEIGHT/2; layer.masksToBounds=YES; layer.borderColor=[UIColor whiteColor].CGColor; layer.borderWidth=2; layer.delegate=self; [self.view.layer addSublayer:layer]; [layer setNeedsDisplay]; } -(void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx { CGContextSaveGState(ctx); CGContextScaleCTM(ctx, 1, -1); CGContextTranslateCTM(ctx, 0, -PHOTO_HEIGHT); UIImage *image=[UIImage imageNamed:@"1"]; CGContextDrawImage(ctx, CGRectMake(0, 0, PHOTO_HEIGHT, PHOTO_HEIGHT), image.CGImage); CGContextRestoreGState(ctx); }