UIAlertController contentViewController

    override func bindViewModel() {
        nextButton.rx.tap.sink { _ in
            Toolbox.addShadowMask()
            let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
            let cancelAction = UIAlertAction(title: "Common_Cancel".localized(), style: .cancel) { _ in
                Toolbox.removeShadowMask()
            }
            let sureAddressAction = UIAlertAction(title: "", style: .default, handler: { _ in
                Toolbox.removeShadowMask()
                SceneAgent.popToViewController(for: ProfileViewController.self, animated: false)
                SceneAgent.pushPhoneOrEmailEdit(type: .emailNoVerified)
            })
            let updateAddressAction = UIAlertAction(title: "Quick_Access_Card_Update_Address".localized(), style: .default, handler: { _ in
                Toolbox.removeShadowMask()
                SceneAgent.popToViewController(for: ProfileViewController.self, animated: false)
                SceneAgent.pushPhoneOrEmailEdit(type: .emailNoVerified)
            })
            alertController.setValue(AlertHeaderViewController(), forKey: "contentViewController")
            sureAddressAction.setValue(AlertActionViewController(), forKey: "contentViewController")
            alertController.addAction(cancelAction)
            alertController.addAction(sureAddressAction)
            alertController.addAction(updateAddressAction)
            SceneAgent.present(vc: alertController, animated: true)
        }.disposed(by: rx.disposeBag)
    }

class AlertHeaderViewController: UIViewController {
   
    private lazy var titleLabel = UILabel().then {
        $0.attributedText = attributedText("""
            \(SettingViewModel.userAddrees, .font(UIFont.cheeseFont("SFProText-Regular", size: 13.pt)), .color(Theme.BlueGreyColor5), .alignment(.center))
            """)
        $0.numberOfLines = 0
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.addSubview(titleLabel)
    
        titleLabel.snp.makeConstraints { make in
            make.leading.trailing.equalToSuperview()
            make.height.equalTo(70)
            make.top.equalTo(10)
            make.bottom.equalTo(-10)
        }
    }
}

class AlertActionViewController: UIViewController {
   
    private lazy var actionButton = UIButton().then {
        $0.setImage(UIImage(named: "contactless_card")?.withRenderingMode(.alwaysOriginal), for: UIControl.State())
        $0.setTitle("Quick_Access_ActionSheet_ConfirmButtonTile".localized(), for: UIControl.State())
        $0.setTitleColor(UIColor.colorForHex("007AFF"), for: UIControl.State())
        $0.imageEdgeInsets = UIEdgeInsets(top: 0, left: -20, bottom: 0, right: 0)
        $0.titleLabel?.font = .H1Medium
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.addSubview(actionButton)
    
        actionButton.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }
}

extension UIAlertController {
    static var propertyNames: [String] {
        var outCount: UInt32 = 0
        guard let ivars = class_copyIvarList(self, &outCount) else {
            return []
        }
        var result = [String]()
        let count = Int(outCount)
        for i in 0..<count {
            let pro: Ivar = ivars[i]
            guard let ivarName = ivar_getName(pro) else {
                continue
            }
            guard let name = String(utf8String: ivarName) else {
                continue
            }
            result.append(name)
        }
        return result
    }
}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容