Advertisement
Guest User

Boat com sobra do Luan

a guest
Dec 18th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.59 KB | None | 0 0
  1. import UIKit
  2.  
  3. class ViewController: UIViewController {
  4.  
  5.     @IBOutlet weak var button : UIButton!
  6.    
  7.     override func viewDidLoad() {
  8.         super.viewDidLoad()
  9.         // Do any additional setup after loading the view, typically from a nib.
  10.         button.setShadowStyle()
  11.     }
  12.  
  13.     override func didReceiveMemoryWarning() {
  14.         super.didReceiveMemoryWarning()
  15.         // Dispose of any resources that can be recreated.
  16.     }
  17.    
  18. }
  19.  
  20.  
  21.  
  22. extension UIButton {
  23.     func setShadowStyle() {
  24.         self.addTarget(self, action: #selector(pressUnshadowEffect), for: UIControlEvents.touchDown)
  25.         self.addTarget(self, action: #selector(pressShadowEffect), for: UIControlEvents.touchUpInside)
  26.         self.shadeButton()
  27.     }
  28.    
  29.     func shadeButton() {
  30.         self.layer.shadowOffset = CGSize(width: 0, height: 0)
  31.         self.layer.shadowColor = UIColor.black.cgColor
  32.         self.layer.shadowOpacity = 1.0
  33.         self.layer.shadowRadius = 3.0
  34.         self.layer.masksToBounds = false
  35.     }
  36.    
  37.     func unshadeButton() {
  38.         self.layer.shadowOffset = CGSize(width: 0, height: 0)
  39.         self.layer.shadowColor = UIColor.clear.cgColor
  40.         self.layer.shadowOpacity = 0.0
  41.         self.layer.shadowRadius = 0.0
  42.         self.layer.masksToBounds = false
  43.     }
  44.    
  45.     @objc func pressShadowEffect() {
  46.         UIView.performWithoutAnimation { [unowned self] in
  47.             self.shadeButton()
  48.         }
  49.     }
  50.    
  51.     @objc func pressUnshadowEffect() {
  52.         UIView.performWithoutAnimation { [unowned self] in
  53.             self.unshadeButton()
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement