ios 开发:布局之 tab bar, navigator
访问量: 3196
这两个都跟 html中的很像。
html 中的 tab 会切换两个DIV, 而 ios 中tab bar (UITabBarControllers) 也是一样:会切换多个controller 对应的view.
# in your app_delegate: class AppDelegate def application(application, didFinishLaunchingWithOptions:launchOptions) @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds) @window.makeKeyAndVisible controller = TapController.alloc.initWithNibName(nil, bundle: nil) nav_controller = UINavigationController.alloc.initWithRootViewController controller other_controller = UIViewController.alloc.initWithNibName nil, bundle: nil other_controller.title = 'Other' other_controller.view.backgroundColor = UIColor.purpleColor tab_controller = UITabBarController.alloc.initWithNibName nil, bundle: nil tab_controller.viewControllers = [nav_controller, other_controller] @window.rootViewController = tab_controller true end end
navigator (UINavigationControllers) 则是页面最上方的 “前进”, “后退”一样的东东。
# in your view controller def viewDidLoad right_button = UIBarButtonItem.alloc.initWithTitle 'Push', style: UIBarButtonItemStyleBordered, target: self, action: 'push' self.navigationItem.rightBarButtonItem = right_button end