使用IB的UIToolbar里面的UILabel在运行时是不可见的,怎么修复? [英] UILabel inside a UIToolbar using IB is invisible on run, how fix?
问题描述
我想在工具栏中显示总数。我把UILabel放在工具栏的顶部。
I want to show a total inside a toolbar. I put in IB the UILabel on top of the toolbar .
然而,当我运行应用程序时,UILabel完全不可见(但可以在代码上设置值很好)。
However, when I run the app, the UILabel is totally invisible (but can set values on code fine).
最离奇的是,在其他形式下,一切正常。我不明白为什么在一种形式的工作,而不是在另一种形式...
The most bizarre thing is that in other form, all work fine. I don't see why in one form work but not in another...
任何想法如何解决这个问题?或者为什么会发生这种情况?
Any idea in how fix this? Or why is this behaviour happening?
推荐答案
不要使用UILabel。
Don't use a UILabel.
使用UIBarButtonItem。然后将其设置为样式:plain。它看起来像一个标签,但它实际上是无边框按钮。这是在条形图上显示文本的一般做法。
Use a UIBarButtonItem. Then set it to style: plain. It looks like a label, but it actually borderless button. This is the general practice of displaying text on a bar.
您还可以在代码中使用自定义视图创建UIBarButtonItem。您可以在UIBarButtonItem中简单地包装UILabel,从而允许您向工具栏添加任何内容。
You can also create UIBarButtonItem with a custom view in code. You are simple "wrapping" the UILabel in a UIBarButtonItem allowing you to add anything you want to a tool bar.
要添加以回应评论:
无论哪种方式,你使按钮无效,它不响应触摸。即使它是一个按钮,它似乎也不是一个按钮。这就是Apple期望将工具栏/导航栏添加视图的方式,以便将事物放在其上。它违反了没有HIG指南,相反,它是一种推荐的设计技术。
Either way, you make the button "inactive" and it doesn't respond to touches. Even though it is a button, it doesn't appear to be one. This is how Apple expects to add views to a toolbar/navbar as apposed to "float things on top of it". It violates no HIG guidelines, much the opposite, it is a reccomended design technique.
要停止发光:
以编程方式创建按钮,确保它是禁用,将其添加到栏中,然后应禁用它,但不要暗淡。
To stop the glow: Create the button programmatically, make sure it is disabled, add it to the bar, it should then be disabled, but not dim.
这篇关于使用IB的UIToolbar里面的UILabel在运行时是不可见的,怎么修复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!