views:

1160

answers:

2

I want to show a total inside a toolbar. I put in IB the UILabel on top of the toolbar .

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?

A: 

In IB, have you tried to select the label and use the "Bring to Font" menu item (under Layout)? It seems like you are trying to do something pretty standard.

When you try to set values, is the label coming up as nil or at address 0x0? It's possible that the label is there, but its text cannot be set because its instance is faulty (not properly connected in IB to the IBOutlet).... Just put a breakpoint on the line where you are trying to set the value(s) for the label, and verify that the label variable is not nil (or 0x0). If it's not, try setting the text and verify on the next line that its text was set properly.

Dutchie432
+3  A: 

Don't use a UILabel.

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.

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.


To add in response to comment:

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.

Corey Floyd
Good thinking. This is probably a better answer than mine :)
Dutchie432
I do that before, but then I think that violate the Apple UI guidelines, because I can click in the label and behave as a button, and I don't know how make it to simply be informative and not respond to user actions.But if is ok, then is the best solution.
mamcx
You make the button inactive and it isn't really a button any more. This is how it is intended to be used.
Corey Floyd
Ok, I do that, but the lable become grey. Is possible to set a white color?
mamcx
I believe the workaround for this is: Create the button programmatically, make sure it is disabled, add it to the bar, it should then be disabled, but not dim.
Corey Floyd
That workaround does not seem to work. When setting barButtonItem.enabled = NO, the glow effect does not happen when the "label" is tapped, but the text is dim.
GregInYEG