mamcx
mamcx

Reputation: 16186

UILabel inside a UIToolbar using IB is invisible on run, how fix?

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?

Upvotes: 5

Views: 6135

Answers (3)

Vaibhav Saran
Vaibhav Saran

Reputation: 12908

drag a UIButton into your UIToolBar. Then uncheck User Interaction Enables for this button.

Customize your UIButton so that it will look like a UILabel. Hope this will help you.

UILabel into a UIToolbar

Upvotes: 0

Corey Floyd
Corey Floyd

Reputation: 25969

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.

Upvotes: 21

Dutchie432
Dutchie432

Reputation: 29160

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.

Upvotes: 0

Related Questions