I have the following CALayer:
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = CGRectMake(8, 57, 296, 30);
gradient.cornerRadius = 3.0f;
gradient.colors = [NSArray arrayWithObjects:(id)[RGB(130, 0, 140) CGColor], (id)[RGB(108, 0, 120) CGColor], nil];
[self.layer insertSublayer:gradient atIndex:0];
I'd like to add an inner shadow effect to it, but I am not quite sure how to do this. I suppose I would be required to draw in drawRect, however this would add the layer on top of other UIView objects, since it's supposed to be a bar behind some buttons, so I am at a loss as to what to do?
I could add another layer, but again, not sure how to achieve the inner shadow effect (like this:
Help appreciated...
Here is a version of swift, change
startPoint
andendPoint
to make it on each side.I'm very late to the the party but I'd like to give back to the community.. This is a method I wrote to remove UITextField background Image as I was supplying a Static Library and NO Resources... I used this for a PIN Entry screen of four UITextField instances that could display One character raw or (BOOL)[self isUsingBullets] or (BOOL)[self usingAsterisks] in ViewController. App is for iPhone/iPhone retina/iPad/iPad Retina so I do not have to supply four images...
I hope this helps someone as this forum has helped me.
This is your solution, which I've exported from PaintCode :
Check the great article of Inner Shadows in Quartz by Chris Emery wich explains how the inner shadows are drawn by PaintCode and gives a clean and neat code snippet:
Here is my solution in Swift 4.2. Would you want to try?
There's a simple solution - just draw the normal shadow and rotate, like this