Swift UINavigationController(导航控制器)的创建及导航栏的设置

Swift UINavigationController(导航控制器)的创建及导航栏的设置,第1张

概述Swift语言新建的项目入口为AppDelegate.swift 我们找到 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool 来创建导航控制器 let VC=ViewController(

Swift语言新建的项目入口为AppDelegate.swift

我们找到

 func application(application: UIApplication,dIDFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool 

来创建导航控制器
        let VC=VIEwController()                let navigationC=UINavigationController(rootVIEwController: VC)        self.window?.rootVIEwController=navigationC                self.window?.backgroundcolor=UIcolor.whitecolor()                return true

我们如果没有动过默认的VIEwController.swift 那么会出来如下效果

会发现上变多另一个导航栏


下边我们尝试设置一下导航栏

我们在VIEwController的vIEwDIDLoad中设置

        //设置设置导航栏标题        self.title="主页"        //设置导航栏背景色        self.navigationController?.navigationbar.barTintcolor=UIcolor.graycolor()//        //导航栏还可以设置图片.//        self.navigationController?.navigationbar.setBackgroundImage(UIImage(named: "testnavigationbar"),forbarMetrics: UIbarMetrics.Default)


下边我们给VIEwController添加子视图

        //添加VIEw        let vIEw1=UIVIEw(frame: CGRectMake(100,2,120,120))        vIEw1.backgroundcolor=UIcolor.redcolor()        self.vIEw.addSubvIEw(vIEw1)


我们会发现子视图被导航栏遮挡了


这是因为坐标系统是从左上角开始的,我们将子视图y坐标设置为20就跑到导航栏下方去了

这是的可以通过修改坐标来实现

也可以设置导航栏属性来实现

        self.navigationController?.navigationbar.translucent=false

同时我们还能隐藏导航栏
        self.navigationController?.navigationbarHIDden=true

常用的功能我就先说到这里

欢迎加群讨论过学习

苹果开发群 :414319235 欢迎加入 欢迎讨论问题

总结

以上是内存溢出为你收集整理的Swift UINavigationController(导航控制器)的创建及导航栏的设置全部内容,希望文章能够帮你解决Swift UINavigationController(导航控制器)的创建及导航栏的设置所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1084565.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存