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
| extension UIViewController { | |
| func add(_ child: UIViewController) { | |
| addChildViewController(child) | |
| view.addSubview(child.view) | |
| child.didMove(toParentViewController: self) | |
| } | |
| func remove() { | |
| guard parent != nil else { | |
| return |
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
| extension UIColor { | |
| convenience init(hex: Int, alpha: Double = 1.0) { | |
| let r = CGFloat((hex & 0xFF0000) >> 16) / 255.0 | |
| let g = CGFloat((hex & 0x00FF00) >> 8) / 255.0 | |
| let b = CGFloat(hex & 0x0000FF) / 255.0 | |
| self.init(red: r, green: g, blue: b, alpha: CGFloat(alpha)) | |
| } | |
| } |
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
| extension UIColor { | |
| convenience init(hex: Int, alpha: Double = 1.0) { | |
| let r = CGFloat((hex & 0xFF0000) >> 16) / 255.0 | |
| let g = CGFloat((hex & 0x00FF00) >> 8) / 255.0 | |
| let b = CGFloat(hex & 0x0000FF) / 255.0 | |
| self.init(red: r, green: g, blue: b, alpha: CGFloat(alpha)) | |
| } | |
| } |
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
| extension UIScreen { | |
| var screenwidth: CGFloat { | |
| return UIScreen.main.bounds.size.width | |
| } | |
| var screenHeight: CGFloat { | |
| return UIScreen.main.bounds.size.height | |
| } | |
| } |
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
| extension UIWebView { | |
| var userAgent: String { | |
| get { | |
| return self.stringByEvaluatingJavaScript(from: "navigator.userAgent")! | |
| } | |
| } |
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
| extension UITextView { | |
| public func clear() { | |
| text = "" | |
| attributedText = NSAttributedString(string: "") | |
| } | |
| public func scrollToBottom() { | |
| let range = NSMakeRange((text as NSString).length - 1, 1) | |
| scrollRangeToVisible(range) |
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
| extension UIView { | |
| // In order to create computed properties for extensions, we need a key to | |
| // store and access the stored property | |
| fileprivate struct AssociatedObjectKeys { | |
| static var tapGestureRecognizer = "MediaViewerAssociatedObjectKey_mediaViewer" | |
| } | |
| fileprivate typealias Action = (() -> Void)? |
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
| extension String { | |
| var html2AttributedString: NSAttributedString? { | |
| do { | |
| return try NSAttributedString(data: Data(utf8), | |
| options: [.documentType: NSAttributedString.DocumentType.html, | |
| .characterEncoding: String.Encoding.utf8.rawValue], | |
| documentAttributes: nil) | |
| } catch { | |
| print("error: ", error) | |
| return nil |
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
| extension UILayoutPriority { | |
| static func +(lhs: UILayoutPriority, rhs: Float) -> UILayoutPriority { | |
| let raw = lhs.rawValue + rhs | |
| return UILayoutPriority(rawValue:raw) | |
| } | |
| } |
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
| extension UITextField { | |
| public var isEmpty: Bool { | |
| if let text = self.text { | |
| return text.isEmpty | |
| } | |
| return true | |
| } | |
| public var trimmedText: String? { |