Skip to content

Instantly share code, notes, and snippets.

@DanielCardonaRojas
Last active December 11, 2020 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanielCardonaRojas/a53e46894e19c9a0293842849beab8d4 to your computer and use it in GitHub Desktop.
Save DanielCardonaRojas/a53e46894e19c9a0293842849beab8d4 to your computer and use it in GitHub Desktop.
UIView general purpuse utilities.
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