Skip to content

Instantly share code, notes, and snippets.

@NarendraPunchh
Last active December 2, 2016 19:40
Show Gist options
  • Save NarendraPunchh/a96a24357df06ae227dd30b264b3a92d to your computer and use it in GitHub Desktop.
Save NarendraPunchh/a96a24357df06ae227dd30b264b3a92d to your computer and use it in GitHub Desktop.
Form shadow
- (CGPathRef)renderRect:(UIView*)imgView {
UIBezierPath *path = [UIBezierPath bezierPathWithRect:imgView.bounds];
return path.CGPath;
}
- (CGPathRef)renderTrapezoid:(UIView*)imgView {
CGSize size = imgView.bounds.size;
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(size.width * 0.33f, size.height * 0.66f)];
[path addLineToPoint:CGPointMake(size.width * 0.66f, size.height * 0.66f)];
[path addLineToPoint:CGPointMake(size.width * 1.15f, size.height * 1.15f)];
[path addLineToPoint:CGPointMake(size.width * -0.15f, size.height * 1.15f)];
return path.CGPath;
}
- (CGPathRef)renderEllipse:(UIView*)imgView {
CGSize size = imgView.bounds.size;
CGRect ovalRect = CGRectMake(0.0f, size.height + 5, size.width - 10, 15);
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:ovalRect];
return path.CGPath;
}
- (CGPathRef)renderPaperCurl:(UIView*)imgView {
CGSize size = imgView.bounds.size;
CGFloat curlFactor = 20.0f;
CGFloat shadowDepth = 8.0f;
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(0.0f, 0.0f)];
[path addLineToPoint:CGPointMake(size.width, 0.0f)];
[path addLineToPoint:CGPointMake(size.width, size.height + shadowDepth)];
[path addCurveToPoint:CGPointMake(0.0f, size.height + shadowDepth)
controlPoint1:CGPointMake(size.width - curlFactor, size.height + shadowDepth - curlFactor)
controlPoint2:CGPointMake(curlFactor, size.height + shadowDepth - curlFactor)];
return path.CGPath;
}
- (void)loadView {
[super loadView];
// Add background tile
UIImage *bgImage = [UIImage imageNamed:@"embedded_bg.png"];
self.view.backgroundColor = [UIColor colorWithPatternImage:bgImage];
// Add the reference view
UIImage *image = [UIImage imageNamed:@"dccp.jpeg"];
UIImageView *imgView = [[UIImageView alloc] initWithImage:image];
[self.view addSubview:imgView];
imgView.center = self.view.center;
imgView.layer.shadowColor = [UIColor colorWithWhite:0 alpha:0.8].CGColor;
imgView.layer.shadowOpacity = 0.7f;
imgView.layer.shadowOffset = CGSizeMake(0.0f, 10.0f);
imgView.layer.shadowRadius = 5.0f;
imgView.layer.masksToBounds = NO;
// imgView.layer.shadowPath = [self renderRect:imgView];
//imgView.layer.shadowPath = [self renderTrapezoid:imgView];
//imgView.layer.shadowPath = [self renderEllipse:imgView];
imgView.layer.shadowPath = [self renderPaperCurl:imgView];
[imgView release];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment