Last active
August 30, 2019 11:55
-
-
Save Zeta611/f36e669220dc65f4c29bec1b654138c2 to your computer and use it in GitHub Desktop.
[CustomViewTemplate] #iOS #template
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 Jay Lee on 05/05/2019. | |
// Copyright © 2019 Jay Lee <jaeho.lee@snu.ac.kr> | |
// This work is free. You can redistribute it and/or modify it under the | |
// terms of the Do What The Fuck You Want To Public License, Version 2, | |
// as published by Sam Hocevar. See http://www.wtfpl.net/ for more details. | |
// | |
import UIKit | |
class CustomView: UIView { | |
// MARK: Public Properties | |
// MARK: Private Properties & IBOutlets | |
@IBOutlet private var view: UIView! // UIButton, UITableViewCell, etc. | |
// MARK: - Initializers | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
commonInit() | |
} | |
required init?(coder aDecoder: NSCoder) { | |
super.init(coder: aDecoder) | |
commonInit() | |
} | |
} | |
// MARK: - Overriden Methods | |
extension CustomView { | |
} | |
// MARK: - Private Methods | |
private extension CustomView { | |
/// A common initializer for a `CustomView` instance. | |
/// | |
/// Instantiates a `CustomView` instance from a `nib` and set it as the `view`. | |
func commonInit() { | |
let bundle = Bundle(for: type(of: self)) | |
let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle) | |
view = nib.instantiate(withOwner: self, options: nil)[0] as? UIView // UIButton, UITableViewCell, etc. | |
view.frame = bounds | |
view.autoresizingMask = [.flexibleWidth, .flexibleHeight] | |
addSubview(view) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment