Created
November 5, 2017 13:29
-
-
Save douglastaquary/7b5ef4839b7e32f7b6d8b3e81aa5465b to your computer and use it in GitHub Desktop.
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
| // | |
| // PopupModelView.swift | |
| import UIKit | |
| protocol PopupModelViewDelegate : class { | |
| func onPopupConfirmation() | |
| func onPopupConfirmationResult(_ result: String) | |
| func onPopupCancelation() | |
| } | |
| class PopupView: UIView { | |
| @IBOutlet weak var view: UIView! | |
| weak var delegate: PopupModelViewDelegate? | |
| override init(frame: CGRect) { | |
| super.init(frame: frame) | |
| xibSetup("\(type(of: self))") | |
| } | |
| required init?(coder aDecoder: NSCoder) { | |
| super.init(coder: aDecoder) | |
| xibSetup("\(type(of: self))") | |
| } | |
| internal func xibSetup(_ named: String) { | |
| view = loadViewFromNib(named) | |
| // use bounds not frame or it'll be offset | |
| view.frame = bounds | |
| // Make the view stretch with containing view | |
| view.autoresizingMask = [UIViewAutoresizing.flexibleWidth, UIViewAutoresizing.flexibleHeight] | |
| // mask layer | |
| let mask = CAShapeLayer() | |
| mask.path = UIBezierPath(roundedRect: view.frame, cornerRadius: 15).cgPath | |
| layer.mask = mask | |
| // Adding custom subview on top of our view (over any custom drawing > see note below) | |
| addSubview(view) | |
| } | |
| internal func loadViewFromNib(_ named: String) -> UIView { | |
| let bundle = Bundle(for: type(of: self)) | |
| let nib = UINib(nibName: named, bundle: bundle) | |
| let view = nib.instantiate(withOwner: self, options: nil)[0] as! UIView | |
| return view | |
| } | |
| // Only override drawRect: if you perform custom drawing. | |
| // An empty implementation adversely affects performance during animation. | |
| override func draw(_ rect: CGRect) { | |
| } | |
| func configureView(_ message: String, buttonLabel: String) { | |
| } | |
| } | |
| extension PopupView { | |
| func onPopupConfirm() { | |
| delegate?.onPopupConfirmation() | |
| } | |
| func onPopupConfirmWithResult(_ result: String) { | |
| delegate?.onPopupConfirmationResult(result) | |
| } | |
| func onPopupCancel() { | |
| delegate?.onPopupCancelation() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment