Search code examples
xcodeios5labeltableviewuitoolbar

IOS 5: How do I add a Label to My TableView's Bottom Bar?


I am trying to add a Label to my bottom bar of my TableView in StoryBoard. But it won't stay when I drag it over. I was able to add a refresh button this way but not the Label. Can I only add buttons to the bottom bar? Thanks!

Edit: Added additional information below.

Image showing bottom toolbar

I made the bottom bar appear by changing the "Bottom Bar" drop down list under "Simulated Metrics" on the right in the picture. I then had the bottom black bar below my table view. I've added a button bar item thats the refresh button. What I'm attempting to do now is add a label to the right of the button so I can show the last time that the information was updated. However, when I attempt to drag a label to that section it doesn't do anything and just goes back the controls window. Thanks!

Update:

I've gotten a little further by adding a "Bar Button Item" and changing it's style to "plain". This gives the visual look almost that I want. Now it would seem I just need to disable the "Button Press" visual where it lights up when touched. Here's a new screenshot showing what I have at the moment.

new label by adding bar button item


Solution

  • I tried the two answers provided but neither worked. To the best of my understanding this is the correct solution. Firstly, I think only UIBarButtonItem's can be added to the UIToolbar. So I added a button and set the style to "Plain". By doing that it sets it to just text. Although the font size was a little big so I fixed that by doing the following...

    [self.lastUpdated setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIFont fontWithName:@"Helvetica" size:14.0f], UITextAttributeFont, nil] forState:UIControlStateNormal];
    

    That code changed the Font to Helvetica and the size to 14.0f. I could also change the text by using self.lastUpdated.title = LastUpdatedText;

    Now the only thing that is left to fix is the glow (light) that shows up when you touch the text. I'm not extremely concerned with this at the moment but seems you can fix this by doing the following I got from the comment of my other question here: iPhone: How to remove glow (light) from UIBarButtonItem when pressed?

    Unfortunately, you can't do it with the standard bar button item. If you want to customize it to that level, you'd have to create a bar button item with a custom view that is actually a button configured the way you want (e.g., no glow) and add that instead of the standard items. - Jason Coco