Created
July 4, 2015 09:12
-
-
Save krishaamer/0065b154ae898af41459 to your computer and use it in GitHub Desktop.
Shadow Effects for UITableView Cells
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
// GuestCellView.swift | |
import UIKit | |
import DynamicColor | |
class GuestCellView:UIView { | |
override func awakeFromNib() { | |
//applyCustomShadow(self) | |
} | |
func applyCurvedShadow(view: UIView) { | |
let size = view.bounds.size | |
let width = size.width | |
let height = size.height | |
let depth = CGFloat(11.0) | |
let lessDepth = 0.8 * depth | |
let curvyness = CGFloat(5) | |
let radius = CGFloat(1) | |
let path = UIBezierPath() | |
// top left | |
path.moveToPoint(CGPoint(x: radius, y: height)) | |
// top right | |
path.addLineToPoint(CGPoint(x: width - 2*radius, y: height)) | |
// bottom right + a little extra | |
path.addLineToPoint(CGPoint(x: width - 2*radius, y: height + depth)) | |
// path to bottom left via curve | |
path.addCurveToPoint(CGPoint(x: radius, y: height + depth), | |
controlPoint1: CGPoint(x: width - curvyness, y: height + lessDepth - curvyness), | |
controlPoint2: CGPoint(x: curvyness, y: height + lessDepth - curvyness)) | |
let layer = view.layer | |
layer.shadowPath = path.CGPath | |
layer.shadowColor = UIColor.blackColor().CGColor | |
layer.shadowOpacity = 0.3 | |
layer.shadowRadius = radius | |
layer.shadowOffset = CGSize(width: 0, height: -3) | |
} | |
func applyHoverShadow(view: UIView) { | |
let size = view.bounds.size | |
let width = size.width | |
let height = size.height | |
let ovalRect = CGRect(x: 5, y: height + 5, width: width - 10, height: 15) | |
let path = UIBezierPath(roundedRect: ovalRect, cornerRadius: 10) | |
let layer = view.layer | |
layer.shadowPath = path.CGPath | |
layer.shadowColor = UIColor.blackColor().CGColor | |
layer.shadowOpacity = 0.2 | |
layer.shadowRadius = 5 | |
layer.shadowOffset = CGSize(width: 0, height: 0) | |
} | |
func applyCustomShadow(view: UIView) { | |
let layer = view.layer | |
let superview = view.superview | |
layer.cornerRadius = 6 | |
layer.masksToBounds = true | |
superview!.layer.backgroundColor = UIColor(hex: 0xffffff).CGColor | |
superview!.layer.shadowPath = UIBezierPath(roundedRect:superview!.bounds, cornerRadius: 12.0).CGPath | |
superview!.layer.shadowColor = UIColor(red: 0, green: 0, blue: 0, alpha:1).CGColor | |
superview!.layer.shadowOffset = CGSize(width: 0, height: 1.0) | |
superview!.layer.shadowOpacity = 0.3 | |
superview!.layer.shadowRadius = 2 | |
superview!.layer.cornerRadius = 12 | |
superview!.layer.masksToBounds = true | |
superview!.clipsToBounds = false | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment