我有一个带有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(取消选择的按钮)。