Skip to content

Instantly share code, notes, and snippets.

@douglastaquary
Created November 5, 2017 13:29
Show Gist options
  • Select an option

  • Save douglastaquary/7b5ef4839b7e32f7b6d8b3e81aa5465b to your computer and use it in GitHub Desktop.

Select an option

Save douglastaquary/7b5ef4839b7e32f7b6d8b3e81aa5465b to your computer and use it in GitHub Desktop.
//
// 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