To add a shadow to a rounded rectangle, you can use the CALayer
property called shadowOpacity
, shadowRadius
, shadowOffset
, and shadowColor
. Here is a sample code that shows you how to add round corners with a shadow in Swift:
main.swift596 chars23 lines
This code creates a rounded rectangle using UIBezierPath
, sets its fillColor
to green, and adds it as a sublayer to the view's layer. It also sets the shadowOpacity, shadowRadius, shadowOffset,
and shadowColor
properties of the layer to create the shadow effect. You can adjust these properties as needed to get the desired result.
gistlibby LogSnag