2016-02-14 63 views
-1

在我的swift 2應用程序中,我必須在項目欄左側的項目。 這是我的代碼:swift在條款項之間設置更多空間

let CloseButton: UIButton = UIButton(type: UIButtonType.Custom) 
      CloseButton.frame = CGRectMake(0, 0, 24, 24) 
      CloseButton.setImage(UIImage(named:"close"), forState: UIControlState.Normal) 
      CloseButton.addTarget(self, action: "close", forControlEvents: UIControlEvents.TouchUpInside) 
      let leftBarCloseButton: UIBarButtonItem = UIBarButtonItem(customView: CloseButton) 

      let EditButton: UIButton = UIButton(type: UIButtonType.Custom) 
      EditButton.frame = CGRectMake(0, 0, 24, 24) 
      EditButton.setImage(UIImage(named:"edit"), forState: UIControlState.Normal) 
      EditButton.addTarget(self, action: "edit", forControlEvents: UIControlEvents.TouchUpInside) 
      let leftBarEditButton: UIBarButtonItem = UIBarButtonItem(customView: EditButton) 

self.navigationItem.setLeftBarButtonItems([leftBarCloseButton,leftBarEditButton], animated: true) 

這就是結果:

enter image description here

我怎樣才能使 「x」 和鉛筆圖標之間有更多的空間?

+0

之間的新欄按鈕項(固定空間)是否增加了邊框的寬度做什麼? – Cole

回答

2

添加這些圖標

var fixedSpace:UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FixedSpace, target: nil, action: nil) 
fixedSpace.width = 10.0 



self.navigationItem.setLeftBarButtonItems([leftBarCloseButton,fixedSpace,leftBarEditButton], animated: true)