通过 CALayer 代理方法绘图

#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(, , PHOTO_HEIGHT, PHOTO_HEIGHT);
layer.position=CGPointMake(, );
layer.backgroundColor=[UIColor redColor].CGColor;
layer.cornerRadius=PHOTO_HEIGHT/;
layer.masksToBounds=YES; layer.borderColor=[UIColor whiteColor].CGColor;
layer.borderWidth=;
layer.delegate=self;
[self.view.layer addSublayer:layer];
[layer setNeedsDisplay]; }
-(void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx
{
CGContextSaveGState(ctx);
CGContextScaleCTM(ctx, , -);
CGContextTranslateCTM(ctx, , -PHOTO_HEIGHT);
UIImage *image=[UIImage imageNamed:@""];
CGContextDrawImage(ctx, CGRectMake(, , PHOTO_HEIGHT, PHOTO_HEIGHT), image.CGImage);
CGContextRestoreGState(ctx);
}

通过 CALayer 代理方法绘图

上一篇:Winform 程序中dll程序集嵌入exe可执行文件


下一篇:用EditPlus和jdk写Java代码