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
func colorWithHexString (hex:String) -> UIColor { | |
var cString:String = hex.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines).uppercased() | |
if (cString.hasPrefix("#")) { | |
let index = cString.index(cString.startIndex, offsetBy: 1) | |
cString = cString.substring(from: index) | |
} | |
if (cString.characters.count != 6) { | |
return UIColor.gray | |
} |
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
extension UIDevice { | |
static var isSimulator: Bool { | |
return ProcessInfo.processInfo.environment["SIMULATOR_DEVICE_NAME"] != nil | |
} | |
} |
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
extension UIColor { | |
convenience init?(hex:String){ | |
var cString:String = hex.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines).uppercased() | |
if (cString.hasPrefix("#")) { | |
let index = cString.index(cString.startIndex, offsetBy: 1) | |
cString = cString.substring(from: index) | |
} | |
if (cString.characters.count != 6) { | |
return nil |
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
func localized(_ string: String) -> String { | |
return NSLocalizedString(string, comment: "") | |
} |
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
extension String { | |
static func random(_ length: Int = 20) -> String { | |
let base = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" | |
var randomString: String = "" | |
for _ in 0..<length { | |
let randomValue = arc4random_uniform(UInt32(base.characters.count)) | |
randomString += "\(base[base.characters.index(base.startIndex, offsetBy: Int(randomValue))])" | |
} |
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 | |
private var viewScrollViewAssociatedKey: UInt8 = 0 | |
extension UIViewController { | |
var scrollViewInternal: UIScrollView! { | |
get { | |
return objc_getAssociatedObject(self, &viewScrollViewAssociatedKey) as? UIScrollView | |
} |
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
func roundCorners(_ corners: UIRectCorner, radius: CGFloat) { | |
let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius)) | |
let mask = CAShapeLayer() | |
mask.path = path.cgPath | |
self.layer.mask = mask | |
} |
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
#!/bin/sh | |
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep ".jsx\{0,1\}$") | |
ESLINT="$(git rev-parse --show-toplevel)/node_modules/.bin/eslint" | |
if [[ "$STAGED_FILES" = "" ]]; then | |
exit 0 | |
fi | |
PASS=true |
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
func loadViewFromNib(nibName: String? = "\(self)") { | |
guard let nibName = nibName else { return } | |
let bundle = Bundle(for: type(of: self)) | |
let nib = UINib(nibName: nibName, bundle: bundle) | |
guard let view = nib.instantiate(withOwner: self, options: nil).first as? UIView else { return } | |
view.frame = bounds | |
view.autoresizingMask = [.flexibleWidth, .flexibleHeight] | |
addSubview(view) | |
} |
OlderNewer