选择时更改 UIBarButtonItem 颜色

Change UIBarButtonItem color when selected

我使用 UIBarButtonItem 的图像,它们是纯白色和透明的。如何在用户选择项目时更改色调颜色?有什么方法可以告诉我在 UIToolBar 中选择了哪个按钮?

当用户点击它时,您可以轻松更改 UIBarButtonItemtintColor

@IBAction func myToolBarButton(sender: AnyObject) {
    myToolBarButton.tintColor = UIColor.greenColor()
}

如果用户一次只能 select 一个按钮,您可能需要使用 UITabBarUITabBar 将更改 select 按钮的 tintColor,然后当您 select 另一个按钮时将按钮更改回默认颜色。

如果您保留 UIToolbar,您将不得不自己处理颜色变化。