宽窄优行-由【嘉易行】项目成品而来
younger_times
2023-07-05 0d8f5fc8a516bfd07e425909e4a4432600572ee7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//
//  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) {
        
    }
}