A Pen by Atsushi Yamamoto on CodePen.
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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
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
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 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 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 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 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 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 UIView { | |
@IBInspectable var borderColor: UIColor? { | |
get { | |
return layer.borderColor.map { UIColor(cgColor: $0) } | |
} | |
set { | |
layer.borderColor = newValue?.cgColor |
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
//////////////////////// | |
// MARK: Array | |
//////////////////////// | |
// map function | |
extension Array { | |
func map<T>(_ transform: (Element) throws -> T) rethrows -> [T] { | |
var result: [T] = [] | |
result.reserveCapacity(count) | |
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 Foundation | |
// MARK: UserDefaults extension | |
extension UserDefaults { | |
struct SomeApp: UserDefaultable { | |
enum UserDefaultKey: String { | |
case someItem | |
} | |
private init() {} |
OlderNewer