- (void)test1
{
UIImage *image = [UIImage imageNamed:@"me"];
CGFloat margin = 10;
CGSize size = CGSizeMake(image.size.width + margin, image.size.height + margin);
UIGraphicsBeginImageContextWithOptions(size, NO, 0);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextAddEllipseInRect(ctx, CGRectMake(0, 0, size.width, size.height));
[[UIColor whiteColor] set];
CGContextFillPath(ctx);
CGFloat smallX = margin * 0.5;
CGFloat smallY = margin * 0.5;
CGFloat smallW = image.size.width;
CGFloat smallH = image.size.height;
CGContextAddEllipseInRect(ctx, CGRectMake(smallX, smallY, smallW, smallH));
CGContextClip(ctx);
[image drawInRect:CGRectMake(smallX, smallY, smallW, smallH)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
self.iv.image = newImage;
NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"aaa.png"];
NSLog(@"%@", path);
NSData *data = UIImagePNGRepresentation(newImage);
[data writeToFile:path atomically:YES];
}
UIColor *color = [UIColor colorWithPatternImage:image];
利用一张图片生成一张背景图片
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint prePoint = [touch previousLocationInView:self];
CGPoint currentPoint = [touch locationInView:self];
CGFloat moveX = currentPoint.x - prePoint.x;
CGFloat moveY = currentPoint.y - prePoint.y;
CGPoint temp = self.center;
temp.x += moveX;
temp.y += moveY;
self.center = temp;
}