1.画图片
- (void)drawRect:(CGRect)rect { // Drawing code UIImage *image = [UIImage imageNamed:@"papa"]; // 在这个点画 [image drawAtPoint:CGPointZero]; // 指定一个区域 [image drawInRect:CGRectMake(10, 10, 50, 50)]; // 在这个范围平铺 [image drawAsPatternInRect:CGRectMake(0, 0, 200, 200)]; }
2.画文字
-(void)drawText{ NSString *text = @"quartz2D入门"; //[text drawAtPoint:CGPointZero withAttributes:nil]; NSDictionary *att = @{NSFontAttributeName:[UIFont systemFontOfSize:15],NSForegroundColorAttributeName:[UIColor redColor]}; [text drawInRect:CGRectMake(10, 10, 120, 44) withAttributes:att]; }