如何将 UIActivityIndi​​catorView 放在导航栏按钮的顶部 (rightBarButtonItem/leftBarButtonItem)

How do I put a UIActivityIndicatorView on top of a NavigationBar button (rightBarButtonItem/leftBarButtonItem)

我有一个导航栏和一个 rightBarButtonItem。

当有人点击这个按钮时,我想在它上面放一个 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)

使用UIBarButtonItem(customView:)。两种方式:

  1. rightBarButtonItem 的两个 UIBarButtonItem 之间切换。
  2. 在两个 customView 之间切换以获得与 rightBarButtonItem 相同的 UIBarButtonItem