navigation left item or right item

 //加左边按钮

    var leftBtn:UIButton?

    var rightBtn: UIBarButtonItem ?


    func setupLeftBarButtonItem(){

        

        let btn1 =UIButton.init(frame:CGRectMake(0,0,50,30))

        btn1.setTitle("完成", forState: UIControlState.Normal)

        btn1.setTitleColor(UIColor.blueColor(), forState:UIControlState.Normal)

        btn1.addTarget(self, action:#selector(ListViewController.leftButton), forControlEvents:UIControlEvents.TouchUpInside)

        let item1 =UIBarButtonItem.init(customView: btn1)

        self.navigationItem.leftBarButtonItem = item1

        

        self.leftBtn =UIBarButtonItem.init(title:"left", style: UIBarButtonItemStyle.Plain, target:self, action:#selector(ListViewController.leftButton))

        

        

    }




  

//    加右边按钮

    func setupRightBarButtonItem(){

    

        self.rightBtn =UIBarButtonItem.init(title:"title", style:UIBarButtonItemStyle.Plain, target:self, action:#selector(ListViewController.rightBarButtonItemClicked))

        self.navigationItem.rightBarButtonItem = self.rightBtn

    }

    






你可能感兴趣的:(ios,Navigation)