A Pen by Atsushi Yamamoto on CodePen.
This file contains hidden or 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 | |
| extension UIViewController { | |
| func hideKeyboardWhenTappedAround() { | |
| let tap = UITapGestureRecognizer(target: self, action: #selector(UIViewController.dismissKeyboard)) | |
| view.addGestureRecognizer(tap) | |
| } | |
| @objc func dismissKeyboard() { |
This file contains hidden or 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 | |
| extension UIColor { | |
| convenience init(hex: Int, alpha: CGFloat = 1.0) { | |
| let max = 255 | |
| let red = CGFloat((hex & 0xFF0000) >> 16 / max) | |
| let green = CGFloat((hex & 0x00FF00) >> 8 / max) | |
| let blue = CGFloat((hex & 0x0000FF) / max) | |
This file contains hidden or 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
| class Transaction { | |
| static let shared = Transaction() | |
| func buy(_ item: String) { | |
| print("You bought \(item).") | |
| } | |
| func sell(_ item: String) { | |
| print("You sold \(item).") | |
| } | |
| } |
This file contains hidden or 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 Foundation | |
| import UIKit | |
| public class Checkmark: UIView { | |
| // MARK: Public variables | |
| public var initialLayerColor: UIColor = UIColor.blue { | |
| didSet { | |
| initialLayer.strokeColor = initialLayerColor.cgColor | |
| } |
This file contains hidden or 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
| let frame = CGRect(x: 0, y: 0, width: 380, height: 600) | |
| let view = UIView(frame: frame) | |
| let gradient = CAGradientLayer() | |
| gradient.frame = frame | |
| gradient.colors = [UIColor.blue.cgColor, UIColor.green.cgColor] | |
| gradient.startPoint = CGPoint(x: 0.408, y: 0) | |
| gradient.endPoint = CGPoint(x: 0.746, y: 1) | |
| view.layer.addSublayer(gradient) |
This file contains hidden or 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
| // Use Gists to store code you would like to remember later on | |
| console.log(window); // log the "window" object to the console |
NewerOlder