Как я могу изменить цвет оттенка моих кнопок после выбора кнопки в боковом меню? - PullRequest
0 голосов
/ 03 июля 2019

У меня есть вид стека с 6 кнопками для навигации. Когда пользователь выбирает меню гамбургера, он также может перемещаться оттуда. У меня уже есть IBAction со всеми моими buttons, и после выбора одного titleColor меняется.

@IBAction func onTapChangeColor(_ sender: UIButton) {
    buttons.forEach {
        $0.setTitleColor( $0 == sender ? .orange : .white, for: .normal)
    }
}

Как я могу реализовать такое же поведение для моего бокового меню? Как я могу получить доступ ко всем делам в моем Enum?

func transitionToNew(_ menuType: MenuType) {

    topView?.removeFromSuperview()

    switch menuType {
    case .pläne:
        let newx = planButton.frame.origin.x
        let storyBoard = UIStoryboard(name: "Main", bundle: nil)
        let planVC = storyBoard.instantiateViewController(withIdentifier: "PlansViewController2") as! PlansViewController2
        self.movingView.frame.origin.x = newx
        addChildView(viewController: planVC, in: scrollView)

    case .dokumentationen:
        let newx = documentationButton.frame.origin.x
        let storyBoard = UIStoryboard(name: "Main", bundle: nil)
        let documentationVC = storyBoard.instantiateViewController(withIdentifier: "DocumentationListViewCtrl") as! DocumentationListViewController
        self.movingView.frame.origin.x = newx
        addChildView(viewController: documentationVC, in: scrollView)
    case .begehungen:
        let newx = visitListButton.frame.origin.x
        let storyBoard = UIStoryboard(name: "Main", bundle: nil)
        let visitlistVC = storyBoard.instantiateViewController(withIdentifier: "VisitListViewController") as! VisitListViewController
        self.movingView.frame.origin.x = newx
        addChildView(viewController: visitlistVC, in: scrollView)
    case .dokumente:
        let newx = documentButton.frame.origin.x
        let storyBoard = UIStoryboard(name: "Main", bundle: nil)
        let documentVC = storyBoard.instantiateViewController(withIdentifier: "DocumentListViewController") as! DocumentListViewController
        self.movingView.frame.origin.x = newx
        addChildView(viewController: documentVC, in: scrollView)
    case .bautagesberichte:
        let newx = constructDiaryButton.frame.origin.x
        let storyBoard = UIStoryboard(name: "Main", bundle: nil)
        let constructdiaryVC = storyBoard.instantiateViewController(withIdentifier: "PlanPreviewViewController") as! PlanPreviewViewController
        self.movingView.frame.origin.x = newx
        addChildView(viewController: constructdiaryVC, in: scrollView)
    case .plankorrekturen:
        let newx = plancorrectionButton.frame.origin.x
        let storyBoard = UIStoryboard(name: "Main", bundle: nil)
        let plancorrectionVC = storyBoard.instantiateViewController(withIdentifier: "PlanCorrectionViewController") as! PlanCorrectionViewController
        self.movingView.frame.origin.x = newx
        addChildView(viewController: plancorrectionVC, in: scrollView)
    case .sync:
        let storyBoard = UIStoryboard(name:"Main", bundle:nil)
        let mainNavCtrl : UIViewController?
        if(GlobalState.lastSync != Date.distantPast) {
            mainNavCtrl = storyBoard.instantiateViewController(withIdentifier: "SyncProgressCtrl")
        } else {
            mainNavCtrl = storyBoard.instantiateViewController(withIdentifier: "LoginViewController")
        }
        MainWindowManager.rootViewController = mainNavCtrl
    case .einstellungen:
        let settingsFormViewCtrl = SettingsFormViewController()
        view.addSubview(settingsFormViewCtrl.view)
        self.topView = settingsFormViewCtrl.view
        addChildViewController(settingsFormViewCtrl)
    case .info:
        let infoVC = InfoFormViewController()
        view.addSubview(infoVC.view)
        self.topView = infoVC.view
        addChildViewController(infoVC)
    }
}

titleColor должен измениться на .orange для новой кнопки и .white для невыбранной кнопки.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...