navigation bar right bar button items spacing

前端 未结 10 2272
执念已碎
执念已碎 2021-01-31 16:47

I have created a with left bar button item added from storyboard, titleView and three right bar button items from code.

Here is the code:

override func         


        
10条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-31 17:20

    // create three nav bar buttons
        var searchBtn = UIBarButtonItem(image: searchImage, style: UIBarButtonItemStyle.Plain, target: self, action: Selector("searchBtnPressed"))
        searchBtn.tintColor = UIColor.whiteColor()
        var clipBtn = UIBarButtonItem(image: clipImage, style: UIBarButtonItemStyle.Plain, target: self, action: Selector("clipBtnPressed"))
        clipBtn.tintColor = UIColor.whiteColor()
        var pencilBtn = UIBarButtonItem(image: pencilImage, style: UIBarButtonItemStyle.Plain, target: self, action: Selector("pencilBtnPressed"))
        pencilBtn.tintColor = UIColor.whiteColor()
    
    // create a spacer
      var space = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: self, action: nil)
      space.width = 10
    
      var buttons = [pencilBtn, space, clipBtn, space, searchBtn]
      navigationItem?.rightBarButtonItems = buttons
    

提交回复
热议问题