2016-11-01 74 views
0

在我的項目中,我想在顯示底部的工具欄中添加按鈕。Swift將按鈕移回工具欄?

我有我的UIViewController嵌入導航控制器,也有我的底部工具欄。但後退按鈕默認位於導航控制器的左上角。

+0

爲什麼要改變蘋果的UI指南建議是什麼? – NRitH

+0

不是我的慾望,但我同意:/ –

回答

1

你不能將按鈕從navBat移回工具欄,但你可以添加自定義按鈕。

self.tabBarController?.navigationItem.hidesBackButton = true 
self.navigationController?.toolbarHidden = false 
var items = [UIBarButtonItem]() 
items.append(
    UIBarButtonItem(title: "Back", style: .Plain, target: self, action: #selector(gotoBack)) 
) 
self.navigationController?.toolbar.items = items 

,並添加到視圖控制器功能

func gotoBack(){ 
    self.navigationController?.popViewController(animated: true) 
} 
0

定製navigationController

雨燕3.0

NavViewController.swift

class NavViewController: UINavigationController,UINavigationControllerDelegate { 

    var _delegate:UIGestureRecognizerDelegate? 


    override func viewDidLoad() { 
     super.viewDidLoad() 

     _delegate = self.interactivePopGestureRecognizer?.delegate 
     self.delegate = self 

    } 



     func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) { 
//Because it can slide 
      if viewController != navigationController.viewControllers[0] { 
       viewController.navigationController?.interactivePopGestureRecognizer?.delegate = nil; 
      }else{ 
       viewController.navigationController?.interactivePopGestureRecognizer?.delegate = _delegate; 
      } 
     } 
    } 

在NextViewC ontroller.swift

override func viewDidLoad() { 
     super.viewDidLoad() 
     self.navigationItem.hidesBackButton = true 
     // Do any additional setup after loading the view. 
    } 
    @IBAction func BackButtonItem(_ sender: UIBarButtonItem) { 
     _ = navigationController?.popViewController(animated: true) 
    } 
0
let toolbar = UIToolbar (frame: CGRect(x: 0, y: 0, width: 
self.view.frame.size.width, height: 56)) 

    toolbar.barStyle = UIBarStyle.black 
    toolbar.sizeToFit() 

    var items = [UIBarButtonItem]() 

    items.append(
     UIBarButtonItem(title: "Back", style: .plain, target: self, action: #selector(Viewcontroller.BackClicked(sender:))) 
    ) 
    toolbar.setItems(items, animated: true) 
    toolbar.tintColor = UIColor.black 
self.navigationController?.navigationItem.hidesBackButton = true 

self.navigationController?.toolbar.items =項目

func BackClicked(sender: UIBarButtonItem) 

{ 
    _ = navigationController?.popViewController(animated: true) 

}