Category Archives: Swift

How to Create Inner Shadow to a UIView with Swift

After searching a lot on Google and reading answers on stackoverflow and blogs, this is by now my understanding of the relationships between UIView’s different properties:

UIView is based on CALayers, CALayer has a shadow property and can have a mask, the mask is a CGPath, CGPath comprises one or more shapes (arc, rectangle, etc.), and can perform boolean operations (union, subtraction, etc.). This is how it looks after putting above-mentioned theories together:

UIView inner shadow
Applying inner shadow to UIView

Example code: