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
| // MARK: - KVO | |
| var observedPaths: [String] = [] | |
| // Usage - observeKVO(keyPath: #keyPath(camera.inputCamera.whiteBalanceMode)) | |
| func observeKVO(keyPath: String) -> Bool { | |
| if shouldObserveKVO { | |
| if self.classForCoder.automaticallyNotifiesObservers(forKey: keyPath) { | |
| observedPaths.append(keyPath) | |
| addObserver(self, forKeyPath: keyPath, options: [.old, .new], context: 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 UIView { | |
| func blur() { | |
| let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.light) | |
| let blurEffectView = UIVisualEffectView(effect: blurEffect) | |
| blurEffectView.frame = self.bounds | |
| blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight] | |
| self.addSubview(blurEffectView) | |
| } | |
| func unBlur() { |
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
| func imageByNormalizingOrientation() -> UIImage { | |
| if imageOrientation == .up { | |
| return self | |
| } | |
| UIGraphicsBeginImageContextWithOptions(size, false, scale) | |
| draw(in: CGRect(origin: CGPoint.zero, size: size)) | |
| let normalizedImage: UIImage? = UIGraphicsGetImageFromCurrentImageContext() | |
| UIGraphicsEndImageContext() | |
| return normalizedImage! | |
| } |
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
| #if !TARGET_INTERFACE_BUILDER | |
| // this code will run in the app itself | |
| #else | |
| // this code will execute only in IB | |
| #endif |
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
| override func prepareForInterfaceBuilder() { | |
| super.prepareForInterfaceBuilder() | |
| titleLabel.text = "Sample title" | |
| imageView.image = UIImage(named: "defaultProfile") | |
| } |
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
| @IBDesignable class NMView: UIView { | |
| override func draw(_ rect: CGRect) { | |
| layer.borderWidth = 1 | |
| // Draw your view | |
| } | |
| override func layoutSubviews() { | |
| super.layoutSubviews() | |
| //Layout your subviews according to reference to self.bounds | |
| } |
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
| class NMView: UIView { | |
| @IBInspectable var text: String? { | |
| didSet { label.text = text } | |
| } | |
| var label: UILabel! | |
| } |
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
| play(sound: "ShortRing", ofType: .wav) |
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
| func disposeSoundIDs() { | |
| for soundID in notificationSoundLookupTable.values { | |
| AudioServicesDisposeSystemSoundID(soundID) | |
| } | |
| } |
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
| var notificationSoundLookupTable = [String: SystemSoundID]() |