如何使用 UIBarButtonSystemItem 更改 UIBarButtonItem 标识符?(迅速) [英] How to use UIBarButtonSystemItem to change UIBarButtonItem identifier? (Swift)

查看:31
本文介绍了如何使用 UIBarButtonSystemItem 更改 UIBarButtonItem 标识符?(迅速)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将带有代码的 UIBarButtonItem 的标识符从播放"更改为暂停".我该怎么做?

I want to change the identifier of an UIBarButtonItem with codes from "Play" to "Pause". How can I do that?

谢谢

推荐答案

1) 初始化一个新按钮

1) init a new button

//change to play
let button = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Play, target: self, action: "someAction")
navigationBar.topItem.leftBarButtonItem = button

//change to pause
let button = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Pause, target: self, action: "someOtherAction")
navigationBar.topItem.leftBarButtonItem = button

2) 只需更改文本:

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

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

If you're also having trouble accessing the navigation bar it is probably best to just set some tag to it (I like to use negative tags for specific Views* to make sure 2 views* don't get the same tag). Then you could fx do like this:

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

这篇关于如何使用 UIBarButtonSystemItem 更改 UIBarButtonItem 标识符?(迅速)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆