【问题标题】:UIBarButtonItem - Make it not clickable when just textUIBarButtonItem - 当只是文本时使其不可点击
【发布时间】:2013-04-25 20:49:57
【问题描述】:

所以我有一个 UIToolbar,上面有 4 个 UIBarButtonItems(其中 2 个是灵活空间),中间的一个是 Style: Plain,标题设置为“设置”,然后最右边的按钮是一个“完成”按钮来关闭视图。

除了中间的文本按钮是“可点击的”之外,一切看起来都很好并且按我想要的方式工作,当你点击它时它什么也不做,但是一旦触摸它就会在文本周围出现白光。

使用 UIBarButtonItem 获得的唯一选项是“启用”,如果将其关闭,则文本会变灰。

我几乎可以通过创建 UILabel 并将其作为子视图添加到 UIToolbar 来模拟它的外观,但我想知道是否有更简单的方法来做到这一点。

谢谢

【问题讨论】:

  • 当你应该使用 UILabel 时,听起来你正在使用 UIBarButtonItem。为什么?

标签: ios objective-c uibarbuttonitem uitoolbar


【解决方案1】:

使用 UIBarButtonItem 的 customView,将 UILabel 设置为 customView。该项目将不可点击。

UILabel *yourLabel = ...;
UIBarButtonItem *theBarItem = [[UIBarButtonItem alloc] initWithCustomView:yourLabel];

就是这样。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-31
    • 1970-01-01
    • 2017-09-28
    • 1970-01-01
    相关资源
    最近更新 更多