Skip to content

Instantly share code, notes, and snippets.

@AkdM
Last active June 18, 2019 14:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AkdM/964d59d1a9060393bde0ed8353dd121b to your computer and use it in GitHub Desktop.
Save AkdM/964d59d1a9060393bde0ed8353dd121b to your computer and use it in GitHub Desktop.
Swift Playground: Corner Radius + Shadow
import UIKit
import PlaygroundSupport
// For the Playground only: creating an UIView where the next UIView will be shown on
let container = UIView(frame: CGRect(x: 0, y: 0, width: 500, height: 500))
container.backgroundColor = .white
// The interesting stuff
let viewShadow = UIView(frame: CGRect(x: 0, y: 0, width: 120, height: 120))
viewShadow.center = container.center
viewShadow.backgroundColor = UIColor.white
viewShadow.layer.shadowColor = UIColor.black.cgColor
viewShadow.layer.shadowOpacity = 0.3
viewShadow.layer.shadowOffset = CGSize(width: 0, height: 8.0) // width = x; height = y
viewShadow.layer.shadowRadius = 10
viewShadow.layer.cornerRadius = 10
container.addSubview(viewShadow)
// For the Playground only: showing it on the Assistant Editor (CMD+Enter to show)
PlaygroundPage.current.liveView = container
PlaygroundPage.current.needsIndefiniteExecution = true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment