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
# addSubview | |
UIView.transition(with: self.view, duration: 0.25, options: [.transitionCrossDissolve], animations: { | |
self.view.addSubview(view) | |
}, completion: nil) | |
# removeFromSuperview | |
UIView.transition(with: self.view, duration: 0.25, options: [.transitionCrossDissolve], animations: { | |
subview.removeFromSuperview() | |
}, completion: 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
import UIKit | |
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" | |
} | |
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 textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { | |
let strippedString = <change replacements string so it fits your requirement - strip, trim, etc> | |
// replace current content with stripped content | |
if let replaceStart = textField.position(from: textField.beginningOfDocument, offset: range.location), | |
let replaceEnd = textField.position(from: replaceStart, offset: range.length), | |
let textRange = textField.textRange(from: replaceStart, to: replaceEnd) { | |
textField.replace(textRange, withText: strippedString) |