Member-only story

How to apply shadow to UIBezierPath

Mr.Javed Multani
2 min readOct 3, 2020

--

Consider a simple rectangle that is drawn by the bezier path.

UIBezierPath* rectanglePath = [UIBezierPath bezierPathWithRect: CGRectMake(x,y,width,height)];
[UIColor.grayColor setFill];
[rectanglePath fill];

Basic Outer-fill shadow:

CGContextRef context = UIGraphicsGetCurrentContext();NSShadow* shadow = [[NSShadow alloc] init];
[shadow setShadowColor: UIColor.blackColor];
[shadow setShadowOffset: CGSizeMake(7.1, 5.1)];
[shadow setShadowBlurRadius: 5];UIBezierPath* rectanglePath = [UIBezierPath bezierPathWithRect: CGRectMake(x,y,width,height)]; CGContextSaveGState(context);
CGContextSetShadowWithColor(context, shadow.shadowOffset, shadow.shadowBlurRadius, [shadow.shadowColor CGColor]);[UIColor.grayColor setFill];
[rectanglePath fill];
CGContextRestoreGState(context);

Basic Inner fill shadow:

CGContextRef context = UIGraphicsGetCurrentContext();NSShadow* shadow = [[NSShadow alloc] init];
[shadow setShadowColor: UIColor.blackColor];
[shadow…

--

--

Mr.Javed Multani
Mr.Javed Multani

Written by Mr.Javed Multani

Software Engineer | Certified ScrumMaster® (CSM) | UX Researcher | Youtuber | Tech Writer

No responses yet