Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 695
mamcx Avatar asked Jun 03 '09 18:06

mamcx


1 Answers

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.

like image 193
Corey Floyd Avatar answered Oct 04 '22 18:10

Corey Floyd