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 { | |
func superview<T>(of type: T.Type) -> T? { | |
return superview as? T ?? superview.flatMap { $0.superview(of: type) } | |
} | |
} | |
// Example usage: | |
func textFieldDidBeginEditing(_ textField: UITextField) { | |
// Get the cell containing the textfield. |
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 NSAttributedString { | |
func highlighting(_ substring: String, using color: UIColor) -> NSAttributedString { | |
let attributedString = NSMutableAttributedString(attributedString: self) | |
attributedString.addAttribute(.foregroundColor, value: color, range: (self.string as NSString).range(of: substring)) | |
return attributedString | |
} | |
} | |
// Usage: |
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 Array { | |
subscript(indexPath: IndexPath) -> Element { | |
self[indexPath.row] | |
} | |
} |
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 | |
extension Array { | |
subscript(indexPath: IndexPath) -> Element { | |
self[indexPath.row] | |
} | |
} |
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 presentAsSheet(_ vc: UIViewController, height: CGFloat) { | |
let presentationController = SheetModalPresentationController(presentedViewController: vc, | |
presenting: self, | |
height: height) | |
vc.transitioningDelegate = presentationController | |
vc.modalPresentationStyle = .custom | |
present(vc, animated: true) | |
} |
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 presentationController = SheetModalPresentationController(presentedViewController: vc, | |
presenting: self, | |
height: height) | |
vc.transitioningDelegate = presentationController | |
vc.modalPresentationStyle = .custom | |
present(vc, animated: true) |
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
interactor.completionSpeed = max(1, velocity / (gestureView.frame.height * (1 / interactor.duration))) |
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 UIView { | |
var allSubviews: [UIView] { | |
subviews + subviews.flatMap { $0.allSubviews } | |
} | |
func firstSubview<T: UIView>(of type: T.Type) -> T? { | |
allSubviews.first { $0 is T } as? T |
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 | |
class LoadingTextField: UITextField { | |
// MARK: Public Properties | |
var spinnerSpeed = 0.75 | |
var spinnerWidth: CGFloat = 3 | |
var spinnerDiameter: CGFloat = 18 | |
var isSpinnerRounded = true |