2015-09-11 70 views
1

我有一個導航欄和一個rightBarButtonItem。我如何將一個UIActivityIndi​​catorView放在NavigationBar按鈕上(rightBarButtonItem/leftBarButtonItem)

當有人點擊這個按鈕時,我想把一個UIActivityIndi​​catorView放在它的頂部,然後我可以在回調完成後加載無論它是否加載。

我將如何實現這一目標?

目前的情況是,我有:

var navBar: UINavigationBar = UINavigationBar(frame: CGRectMake(0, 0, self.view.bounds.width, 64)) 

navBar.barTintColor = UIColor.whiteColor() 
navBar.translucent = false 

navBar.titleTextAttributes = [ NSForegroundColorAttributeName : UIColor.darkGrayColor() ] 

self.view.addSubview(navBar) 

var buttonRight = UIBarButtonItem(image: UIImage(named: "Search"), style: .Plain, target: self, action: Selector("goSearch")) 

buttonRight.tintColor = UIColor(hexString: "056A85") 

var navigationItem = UINavigationItem() 
navigationItem.rightBarButtonItem = buttonRight 

navigationItem.title = title 

navBar.pushNavigationItem(navigationItem, animated: false) 

回答

1

使用UIBarButtonItem(customView:)。兩種方式:

  1. 在兩個UIBarButtonItem之間切換爲rightBarButtonItem
  2. 在兩個customView之間切換爲相同的UIBarButtonItemrightBarButtonItem
相關問題