xcode – 如何使用UIBarButtonSystemItem来更改UIBarButtonItem标识符? (迅速)

前端之家收集整理的这篇文章主要介绍了xcode – 如何使用UIBarButtonSystemItem来更改UIBarButtonItem标识符? (迅速)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想将代码从“播放”更改为“暂停”的UIBarButtonItem的标识符.我怎样才能做到这一点?

谢谢

解决方法

1)初始化一个新按钮
  1. //change to play
  2. let button = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Play,target: self,action: "someAction")
  3. navigationBar.topItem.leftBarButtonItem = button
  4.  
  5. //change to pause
  6. let button = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Pause,action: "someOtherAction")
  7. navigationBar.topItem.leftBarButtonItem = button

2)只需更改文字

  1. navigationBar.topItem?.leftBarButtonItem?.title = "AnyText"

如果您在访问导航栏时遇到问题,最好只设置一些标签(我喜欢使用特定视图的负标签*来确保2个视图*不会获得相同的标签).
然后你可以这样做:

  1. let navigationBar = (self.view.viewWithTag(-1) as UINavigationBar)
  2. navigationBar.topItem?.leftBarButtonItem?.title = "AnyText"

猜你在找的iOS相关文章