It may be a little more complicated than necessary, but here is one solution.
UIView following way:
extension UIView {
Usage, given that the background view is called view :
let shadowView = UIView(frame: CGRect(x: 100, y: 100, width: 300, height: 200)) shadowView.layer.cornerRadius = 15.0 shadowView.dropShadow(view) view.addSubview(shadowView)
The result is the following:

Note. The dropShadow method may not be called from viewDidLoad , as this causes problems with the graphics context. So, use this method at the beginning of viewWillAppear for the result above.
Here is the code for the background view, just in case someone wants to test on the playgrounds:
let view = UIView(frame: CGRect(x: 0, y: 0, width: 500, height: 400)) view.backgroundColor = UIColor.clearColor() let color1 = UIColor(hue: 0.39, saturation: 0.7, brightness: 1.0, alpha: 1.0).CGColor let color2 = UIColor(hue: 0.51, saturation: 0.9, brightness: 0.6, alpha: 1.0).CGColor let gradient = CAGradientLayer() gradient.frame = view.frame gradient.colors = [color1, color2] gradient.startPoint = CGPoint(x: 0, y: 0) gradient.endPoint = CGPoint(x: 1, y: 1) view.layer.insertSublayer(gradient, atIndex: 0)
source share