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

IOS 菜单栏 UITabBarController 常用

作者头像
用户5760343
发布2019-07-07 15:28:01
1.2K0
发布2019-07-07 15:28:01
举报
文章被收录于专栏:sktjsktj

1、创建三个视图控制器 FirstViewController、SecondViewController、ThirdViewController

2、在FirstViewController.swift中viewDidLoad添加 self.title = “Item #1” self.tabBarItem.image = UIImage(named:“Tab1”) let label = UILabel(frame:CGRect(x:40, y:150,width:240, height:44)) label.text = “第一页” label.textAlignment = NSTextAlignment.center label.font = UIFont(name:“Arial”, size:36) self.view.addSubview(label)

3 AppDelegate.swift的didFinishLaunchingWithOptions方法: let firstViewController = FirstViewController() let secondViewController = SecondViewController() let thirdViewController = ThirdViewController() let tabViewController = UITabBarController() tabViewController.viewControllers =[firstViewController, secondViewController,thirdViewController] self.window?.rootViewController = tabViewController

image.png

加右上角提醒:self.tabBarItem.badgeValue="8"

image.png

手动改变tab

1 let button = UIButton(frame:CGRect(x:40, y:220, width:240, height:44)) 2 button.setTitle(“进入第二页”, for:UIControlState()) 3 button.backgroundColor = UIColor.black 4 button.addTarget(self, action:

selector(FirstViewController.enterPage2),

for:.touchUpInside) 5 self.view.addSubview(button) 1 func enterPage2() 2 { 3 self.tabBarController?.selectedIndex = 1 4 }

可以改变导航栏的位置:

let screenWidth = UIScreen.main.bounds.width tabViewController.tabBar.frame = CGRect(x:0, y:0,width:screenWidth, height:44)

隐藏顶部状态栏

info.plist中Status bar is initially hidden=YES View controller-based status bar appearance=NO

image.png

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

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

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

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

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 加右上角提醒:self.tabBarItem.badgeValue="8"
  • 手动改变tab
  • selector(FirstViewController.enterPage2),
  • 可以改变导航栏的位置:
  • 隐藏顶部状态栏
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档