NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor clearColor],UITextAttributeTextColor,
nil]
[[UIBarButtonItem appearance] setTitleTextAttributes:attributes
forState:UIControlStateNormal]
我遇到了同样的问题,我是这样解决的。
--编辑--
如果您真的想要删除所有UIBarbuttonItem的标题文本,则以下是解决方案。如果您只想删除后退栏按钮项的标题,则没有一个简单的便捷解决方案。在我的情况下,由于只有几个UIBarButtonItems需要显示标题文本,因此我只更改了那些特定按钮的titleTextAttributes。如果您想更加具体,请使用下面的代码,它将仅更改导航栏按钮。
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor clearColor],UITextAttributeTextColor,
nil]
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:attributes
forState:UIControlStateNormal]
--编辑--
关于Swift
let BarButtonItemAppearance = UIBarButtonItem.appearance()
BarButtonItemAppearance.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.clear], for: .normal)
BarButtonItemAppearance.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.clear], for: .highlighted)
BarButtonItemAppearance.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.clear], for: .selected)