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

前端 未结 3 1838

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 v

3条回答
  •  醉话见心
    2020-12-30 16:40

    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.

提交回复
热议问题