Skip to content

Instantly share code, notes, and snippets.

@xdream86
Created August 25, 2013 03:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xdream86/6331741 to your computer and use it in GitHub Desktop.
Save xdream86/6331741 to your computer and use it in GitHub Desktop.
/**
* 使用UIKit方式生成路径
*/
///////////////////////////////////////////////////////////////////////////////////////////////////
- (CGPathRef)renderPaperCurl:(UIView*)imgView {
CGSize size = imgView.bounds.size;
CGFloat curlFactor = 12.0f;
CGFloat shadowDepth = 4.0f;
CGFloat translationFactor = 6.0f;
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(0.0f + translationFactor, 0.0f)];
[path addLineToPoint:CGPointMake(size.width - translationFactor, 0.0f)];
[path addLineToPoint:CGPointMake(size.width - translationFactor, size.height + shadowDepth)];
[path addCurveToPoint:CGPointMake(0.0f + translationFactor, size.height + shadowDepth)
controlPoint1:CGPointMake(size.width - translationFactor - curlFactor, size.height + shadowDepth - curlFactor)
controlPoint2:CGPointMake(curlFactor + translationFactor, size.height + shadowDepth - curlFactor)];
return path.CGPath;
}
/**
* 使用Quartz方式生成路径
*/
///////////////////////////////////////////////////////////////////////////////////////////////////
- (CGPathRef)renderPaperCurlPathUsingQuartz:(UIView*)imgView {
CGSize size = imgView.bounds.size;
CGFloat curlFactor = 12.0f;
CGFloat shadowDepth = 4.0f;
CGFloat translationFactor = 6.0f;
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 0.0 + translationFactor, 0.0f);
CGPathAddLineToPoint(path, NULL, size.width - translationFactor, 0.0f);
CGPathAddLineToPoint(path, NULL, size.width - translationFactor, size.height + shadowDepth);
CGPathAddCurveToPoint(path, NULL,
size.width - translationFactor - curlFactor, size.height + shadowDepth - curlFactor,
curlFactor + translationFactor, size.height + shadowDepth - curlFactor,
0.0f + translationFactor, size.height + shadowDepth);
return path;
}
- (void)loadView {
[super loadView];
self.view.backgroundColor = [UIColor colorWithRed:242.0/255.0f green:232/255.0f blue:225/255.0f alpha:1];
UIImage *image = [UIImage imageNamed:@"dccp.jpeg"];
UIImageView *imgView = [[UIImageView alloc] initWithImage:image];
[self.view addSubview:imgView];
imgView.center = self.view.center;
imgView.layer.borderWidth = 4;
imgView.layer.borderColor = [UIColor whiteColor].CGColor;
imgView.layer.shadowColor = [UIColor blackColor].CGColor;
imgView.layer.shadowOpacity = 0.6f;
imgView.layer.shadowOffset = CGSizeMake(0.0f, 4.0f);
imgView.layer.shadowRadius = 1.0f;
imgView.layer.masksToBounds = NO;
imgView.layer.shadowPath = [self renderPaperCurl:imgView];
/*
CGPathRef path = [self renderPaperCurlPathUsingQuartz:imgView];
imgView.layer.shadowPath = path;
CFRelease(path);
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment