Created
January 30, 2016 09:32
-
-
Save r-plus/31f109e44fc81a572192 to your computer and use it in GitHub Desktop.
inner shadow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import XCPlayground | |
extension UIView { | |
public func addInnerShadow(topColor: UIColor = UIColor.blackColor().colorWithAlphaComponent(0.3)) { | |
let shadowLayer = CAGradientLayer() | |
shadowLayer.cornerRadius = layer.cornerRadius | |
shadowLayer.frame = bounds | |
shadowLayer.frame.size.height = 10.0 | |
shadowLayer.colors = [ | |
topColor.CGColor, | |
UIColor.whiteColor().colorWithAlphaComponent(0).CGColor | |
] | |
layer.addSublayer(shadowLayer) | |
} | |
} | |
let baseView = UIView(frame: CGRectMake(0,0, 300,300)) | |
baseView.backgroundColor = UIColor.whiteColor() | |
let view = UIView(frame: CGRectMake(20,20, 100,100)) | |
view.backgroundColor = UIColor.greenColor() | |
view.layer.cornerRadius = 10.0 | |
//view.layer.shadowColor = UIColor.grayColor().CGColor | |
view.layer.shadowOpacity = 1.0 | |
view.layer.shadowOffset = CGSizeMake(0, 1.5) | |
view.layer.shadowRadius = 5.0 | |
view.layer.borderColor = UIColor.greenColor().CGColor | |
view.layer.borderWidth = 1.0 | |
view.addInnerShadow(UIColor.whiteColor().colorWithAlphaComponent(1.0)) | |
baseView.addSubview(view) | |
XCPlaygroundPage.currentPage.liveView = baseView |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment