//
|
// ActionSheetViewController.swift
|
// WashCar
|
//
|
// Created by alvin_y on 2020/7/9.
|
// Copyright © 2020 yangwang. All rights reserved.
|
//
|
|
import Foundation
|
import SwiftEntryKit
|
|
class ActionSheetViewController: YYViewController {
|
|
private let stackView = UIStackView()
|
|
private let actions: [YYAlertKit.Action]
|
|
init(actions: [YYAlertKit.Action]) {
|
self.actions = actions
|
super.init(nibName: nil, bundle: nil)
|
}
|
|
required init?(coder aDecoder: NSCoder) {
|
fatalError("init(coder:) has not been implemented")
|
}
|
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
|
|
}
|
|
override func setupViews() {
|
super.setupViews()
|
|
stackView.axis = .vertical
|
stackView.alignment = .fill
|
stackView.distribution = .fillProportionally
|
view.addSubview(stackView)
|
|
for (index, action) in actions.enumerated() {
|
|
let button = UIButton(type: .system)
|
|
switch action.style {
|
case .plain:
|
button.setTitleColor(#colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.8), for: .normal)
|
case .cancel:
|
button.setTitleColor(#colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.6), for: .normal)
|
}
|
|
button.setTitle(action.title, for: .normal)
|
button.titleLabel?.font = UIFont.systemFont(ofSize: 14)
|
button.clipsToBounds = true
|
button.rx.tap
|
.subscribe(onNext: {
|
SwiftEntryKit.dismiss() {
|
action.action?()
|
}
|
})
|
.disposed(by: disposeBag)
|
stackView.addArrangedSubview(button)
|
|
button.snp.makeConstraints { (make) in
|
make.height.equalTo(50)
|
}
|
|
guard index < actions.count - 1 else { return }
|
let line = UIView()
|
line.backgroundColor = #colorLiteral(red: 0.9647058824, green: 0.9647058824, blue: 0.9647058824, alpha: 1)
|
stackView.addArrangedSubview(line)
|
|
line.snp.makeConstraints { (make) in
|
make.height.equalTo(1)
|
}
|
}
|
}
|
|
override func defineLayouts() {
|
super.defineLayouts()
|
|
stackView.snp.makeConstraints { (make) in
|
make.edges.equalTo(view).inset(UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10))
|
}
|
}
|
|
@objc private func didPressButton(_ sender: UIButton) {
|
|
}
|
}
|