前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >IOS 导航栏 UINavigationController 常用

IOS 导航栏 UINavigationController 常用

作者头像
用户5760343
发布2019-07-07 15:26:07
1.1K0
发布2019-07-07 15:26:07
举报
文章被收录于专栏:sktj

1 创建:FirstViewController、SecondViewController 2、在FirstViewController的viewDidLoad设置属性 override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. self.title = “第一页” self.view.backgroundColor = UIColor.brown self.navigationItem.rightBarButtonItem = UIBarButtonItem(title:”下一页”, style: UIBarButtonItemStyle.plain, target:self, action:

selector(FirstViewController.nextPage))

} func nextPage() { let viewController = SecondViewController() self.navigationController?.pushViewController(viewController, animated:true) } 3、AppDelegate.swift中的didFinishLaunchingWithOptions func application(_ application:UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // Override point for customization after application launch. let viewController = FirstViewController() let navigationController = UINavigationController(rootViewController:viewController) self.window?.rootViewController =navigationController return true } 4、SecondSubViewController.swift import UIKit var pageNum = 0 class SecondViewController:UIViewController { override func viewDidLoad() { super.viewDidLoad() pageNum = pageNum + 1 self.title = “第(pageNum)页” self.view.backgroundColor = UIColor.purple let push = UIButton(frame:CGRect(x:40, y:120, width:240, height:40)) push.setTitle(“Push Page”, for:UIControlState()) push.backgroundColor = UIColor.orange push.addTarget(self, action:

selector(SecondViewController.pushPage), for:

UIControlEvents.touchUpInside) self.view.addSubview(push) let pop = UIButton(frame:CGRect(x:40, y:180, width:240, height:40)) pop.setTitle(“Pop Page”, for:UIControlState()) pop.backgroundColor = UIColor.orange pop.addTarget(self, action:

selector(SecondViewController.popPage), for:

UIControlEvents.touchUpInside) self.view.addSubview(pop) let index = UIButton(frame:CGRect(x:40, y:280,width:240, height:40)) index.setTitle(“Goto Index Page”, for: UIControlState()) index.backgroundColor = UIColor.orange index.addTarget(self, action:

selector(SecondViewController.gotoIndexPage), for:

UIControlEvents.touchUpInside) self.view.addSubview(index) let root = UIButton(frame:CGRect(x:40, y:340, width:240, height:40)) root.setTitle(“Goto Root Page”, for:UIControlState()) root.backgroundColor = UIColor.orange root.addTarget(self, action:

selector(SecondViewController.gotoRootPage), for:

UIControlEvents.touchUpInside) self.view.addSubview(root) } } func pushPage() { let viewController = SecondViewController() self.navigationController?.pushViewController(viewController,animated:true) } func popPage() { self.navigationController?.popViewController(animated:true) } func gotoIndexPage() { let viewController = self.navigationController?.viewControllers[2] self.navigationController?.popToViewController(viewController!, animated:true) } func gotoRootPage() { self.navigationController?.popToRootViewControllerAnimated(animated:true) }

6、更改导航栏的可见性/导航栏样式修改:FirstSubViewController.swift中的viewWillAppear override func viewWillAppear(animated:Bool) { super.viewWillAppear(animated) self.navigationController?.setToolbarHidden(false,animated:false) self.navigationController?.setNavigationBarHidden(true,animated:true) self.navigationItem.prompt = “正在载入……” self.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem:.refresh, target: self, action:#selector(FirstSubViewController.refresh)) self.navigationController?.navigationBar.isTranslucent= false self.navigationController?.navigationBar.barStyle =UIBarStyle.black self.navigationController?.navigationBar.tintColor =UIColor.orange } func refresh() { print(“刷新数据。”) }

image.png

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019.05.31 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • selector(FirstViewController.nextPage))
  • selector(SecondViewController.pushPage), for:
  • selector(SecondViewController.popPage), for:
  • selector(SecondViewController.gotoIndexPage), for:
  • selector(SecondViewController.gotoRootPage), for:
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档