Last active
August 29, 2020 11:04
-
-
Save rsaenzi/1f5b02729ad42e6ca063e9db7d84408d to your computer and use it in GitHub Desktop.
Template for custom view loaded from a .xib file
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
// | |
// CustomView.swift | |
// | |
// Created by Rigoberto Sáenz Imbacuán (https://www.linkedin.com/in/rsaenzi/) | |
// Copyright © 2019. All rights reserved. | |
// | |
// Notes: | |
// - Bind content to the ContentView in Interface Builder | |
// - Make the xib's file owner be this class | |
import UIKit | |
class CustomView: UIView { | |
// This property must be bound to the whole view in Interface Builder | |
@IBOutlet private weak var content: UIView! | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
sharedInit() | |
} | |
required init?(coder aDecoder: NSCoder) { | |
super.init(coder: aDecoder) | |
sharedInit() | |
} | |
private func sharedInit() { | |
loadNib() | |
addSubview(content) | |
// Expand to fill its parent | |
content.frame = self.bounds | |
content.autoresizingMask = [.flexibleHeight, .flexibleWidth] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
UIView+Load.swift
https://gist.github.com/rsaenzi/0c3da9a1f5084c6ac73cee0b501daf33