swift中UINavigationController的使用

swift中UINavigationController的使用,第1张

概述// 导航视图控制器标题self.navigationItem.title = "navigationController" // 导航视图控制器样式self.navigationController!.setNavigationStyleDefault() // 导航视图控制器左按钮self.navigationItem.leftBarButtonIte
// 导航视图控制器标题self.navigationItem.Title = "navigationController"        // 导航视图控制器样式self.navigationController!.setNavigationStyleDefault()        // 导航视图控制器左按钮self.navigationItem.leftbarbuttonItem = UIbarbuttonItem(Title: "present",style: UIbarbuttonItemStyle.Done,target: self,action: Selector("presentClick"))self.navigationItem.leftbarbuttonItem!.tintcolor = UIcolor.greencolor()        // 导航视图控制器右按钮self.navigationItem.rightbarbuttonItem = UIbarbuttonItem(Title: "push",action: Selector("pushClick"))self.navigationItem.rightbarbuttonItem!.tintcolor = UIcolor.orangecolor()
// 注意:如果下个视图控制器的导航栏样式与当前的不一样时,返回当前视图控制器时,需要重置下样式overrIDe func vIEwWillAppear(animated: Bool) {        super.vIEwWillAppear(animated)                // 导航视图控制器样式        self.navigationController!.setNavigationStyleDefault()}
// 导航视图控制器样式self.navigationController!.setNavigationStyle(UIcolor.orangecolor(),textFont: UIFont.boldSystemFontOfSize(12.0),textcolor: UIcolor.yellowcolor())

// 导航栏隐藏,或显示let button = UIbutton(frame: CGRectMake(10.0,10.0,(CGRectGetWIDth(self.vIEw.frame) - 10.0 * 2),40.0))self.vIEw.addSubvIEw(button)button.backgroundcolor = UIcolor.lightGraycolor()button.setTitle("隐藏导航栏",forState: UIControlState.normal)button.setTitlecolor(UIcolor.blackcolor(),forState: UIControlState.normal)button.setTitlecolor(UIcolor.redcolor(),forState: UIControlState.Highlighted)button.addTarget(self,action: Selector("hIDdenClick:"),forControlEvents: UIControlEvents.touchUpInsIDe)button.selected = false
func hIDdenClick(button:UIbutton){        button.selected = !button.selected                let isSelected = button.selected        let text = (isSelected ? "隐藏" : "显示")        print("\(text) 导航栏")                if isSelected        {            button.setTitle("显示导航栏",forState: UIControlState.normal)            self.navigationController!.setNavigationbarHIDden(true,animated: true)        }        else        {            button.setTitle("隐藏导航栏",forState: UIControlState.normal)            self.navigationController!.setNavigationbarHIDden(false,animated: true)        }        }
// 导航栏样式设置方法// MARK: - 导航栏样式设置/// 设置默认导航栏样式func setNavigationStyleDefault(){        self.setNavigationStyle(UIcolor.whitecolor(),textFont: UIFont.boldSystemFontOfSize(18.0),textcolor: UIcolor.blackcolor())}    /// 导航栏样式设置(自定义背景颜色、字体)func setNavigationStyle(backgroundcolor:UIcolor,textFont:UIFont,textcolor:UIcolor){        if self.navigationbar.respondsToSelector(Selector("barTintcolor"))        {            // 背景色            self.navigationbar.barTintcolor = backgroundcolor            self.navigationbar.translucent = false            self.navigationbar.tintcolor = UIcolor.whitecolor()                        // 字体            self.navigationbar.TitleTextAttributes = [NSFontAttributename:textFont,NSForegroundcolorAttributename:textcolor];                        // 导航底部1px的阴影颜色-修改            /*            self.navigationbar.shadowImage = UIImage(named: "")            [self.navigationbar setShadowImage:kImageWithcolor(kcolorSeparatorline)];            */                        // 导航底部1px的阴影-遮住            let maskLayer = CAShapeLayer.init()            maskLayer.backgroundcolor = UIcolor.redcolor().CGcolor;            let maskRect = CGRectMake(0,-20.0,CGRectGetWIDth(self.navigationbar.frame),(20.0 + CGRectGetHeight(self.navigationbar.frame)));            maskLayer.path = CGPathCreateWithRect(maskRect,nil);            self.navigationbar.layer.mask = maskLayer;        }}

总结

以上是内存溢出为你收集整理的swift中UINavigationController的使用全部内容,希望文章能够帮你解决swift中UINavigationController的使用所遇到的程序开发问题。

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

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

原文地址:https://54852.com/web/1070902.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存