Last active
December 11, 2020 17:11
-
-
Save DanielCardonaRojas/a53e46894e19c9a0293842849beab8d4 to your computer and use it in GitHub Desktop.
UIView general purpuse utilities.
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 makeCircular() -> NSKeyValueObservation { | |
self.layer.cornerRadius = self.bounds.width/2 | |
clipsToBounds = true | |
let observation = observe(\UIView.bounds, changeHandler: { this, change in | |
this.layer.cornerRadius = this.bounds.width/2 | |
}) | |
return observation | |
} | |
// MARK: Xib related | |
func loadViewFromNib() -> UIView { | |
let bundle = Bundle(for: type(of: self)) | |
let nib = UINib(nibName: "\(Self.self)", bundle: bundle) | |
let view = nib.instantiate(withOwner: self, options: nil)[0] as! UIView | |
return view | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment