Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 所有选项卡栏控制器的栏按钮_Ios_Swift_Uinavigationcontroller_Uitabbarcontroller - Fatal编程技术网

Ios 所有选项卡栏控制器的栏按钮

Ios 所有选项卡栏控制器的栏按钮,ios,swift,uinavigationcontroller,uitabbarcontroller,Ios,Swift,Uinavigationcontroller,Uitabbarcontroller,我在UITabBarController中嵌入了三个视图控制器。每个视图控制器都嵌入在导航控制器中 我的应用程序的逻辑是在所有选项卡栏视图控制器上都有导航右栏按钮(即从每个视图控制器上都可以看到的“菜单”按钮)。实现这一点的最简单方法是将此按钮分别添加到所有导航控制器。但我认为这不是一个好的解决方案,因为在每个导航控制器中,这个按钮的代码必须重复 有没有办法在UITabBarController的所有控制器上使用相同的导航右键 (在我的应用程序中,我没有使用故事板)您可以创建一个新的UIView

我在UITabBarController中嵌入了三个视图控制器。每个视图控制器都嵌入在导航控制器中

我的应用程序的逻辑是在所有选项卡栏视图控制器上都有导航右栏按钮(即从每个视图控制器上都可以看到的“菜单”按钮)。实现这一点的最简单方法是将此按钮分别添加到所有导航控制器。但我认为这不是一个好的解决方案,因为在每个导航控制器中,这个按钮的代码必须重复

有没有办法在UITabBarController的所有控制器上使用相同的导航右键


(在我的应用程序中,我没有使用故事板)

您可以创建一个新的UIViewController类,该类向其导航控制器的导航栏(例如“菜单”)添加一个栏按钮项。然后,其他视图控制器可以从新的UIViewController类继承。这样,只需编写一次添加条形按钮的代码。

UIAbbarController继承自UIViewController。技术上,您可以在UINavigationController中按下UITabBarController。然后在UIAbbarController中,您可以设置UIBarButtonim。

扩展名UIViewController在项目中的任意位置创建导航栏方法调用。导航栏将显示右键菜单

比如说

    import UIKit

    extension UIViewController {

        func setupNavigationBar(title: String) {
            // back button without title
            //self.navigationController?.navigationBar.topItem?.title = ""

            //back button color
            //self.navigationController?.navigationBar.tintColor = UIColor.white

            //set titile
             self.navigationItem.title =  title

            //set text color & font size
            //self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.init(red: 251/255, green: 251/255, blue: 251/255, alpha: 1) , NSFontAttributeName:UIFont.systemFont(ofSize: 19)]

            //set background color without gradian effect
            //self.navigationController?.navigationBar.barTintColor = UIColor.init(red: 134/255, green: 145/255, blue: 152/255, alpha: 1)

            //show right button 
            let rightButton = UIBarButtonItem(image: #imageLiteral(resourceName: "Menu"), style: .plain, target: self, action: #selector(menu))

            //right Bar Button Item tint color 
            //self.navigationItem.rightBarButtonItem?.tintColor = UIColor.init(red: 219/255, green: 219/255, blue: 219/255, alpha: 1)

            //show the Menu button item
            self.navigationItem.rightBarButtonItem = rightButton

            //show bar button item tint color 
            //self.navigationItem.rightBarButtonItem?.tintColor = UIColor.init(red: 219/255, green: 219/255, blue: 219/255, alpha: 1)

        }

        func menu(){ 
            print("showSlideOutMane fire ")
        }

    }