setting a title to a translucent toolbar

Discussion in 'iOS Programming' started by hassoon, Mar 7, 2013.

  1. hassoon macrumors regular

    Joined:
    Jun 8, 2009
    #1
    i added a toolbar and made it translucent (Bottom) of the screen. now i want to change it's title. i tried so many ways but none worked and it seems that title isn't a property that is included for translucent toolbars. i tried to add a UILabel and it also didn't work cause i couldn't place a Label on a translucent toolbar in the first place. how can i do that?
     
  2. waterskier2007 macrumors 68000

    waterskier2007

    Joined:
    Jun 19, 2007
    Location:
    White Lake, MI
    #2
    Are you talking about a toolbar or navigation bar. Navigation bars contain the title property of the view controller itself. The title property is not part of the navigation bar.

    As for toolbars, I am not sure how or why you would want to set a title on it, as toolbars are for interacting with things like buttons/sliders/etc.
     
  3. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    As you've discovered, there is no title property for UIToolbar. So, perhaps instead of telling us what you think is the solution, you could tell us what problem you're trying to solve and maybe we can come up with some alternatives.
     
  4. hassoon thread starter macrumors regular

    Joined:
    Jun 8, 2009
    #4
    i already stated that, i want to set a title for a translucent toolbar (the one below and not the navigation bar). I've seen it before in some apps where some info is shown below beside being used by tools buttons and stuff. actually the one i saw was being used on a normal blue backgrounded toolbar. so is it possible?
     
  5. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    Yes. Since UIToolbar is a UIView subclass, one approach to consider is just adding a subview to it.
     
  6. hassoon thread starter macrumors regular

    Joined:
    Jun 8, 2009
    #6
    i found a way to do that. i added two flexible spaces and one item. i placed the item in the middle and the spaces to the left/right of it. i created an outlet property for the item so that i can change it's text in code. and i changed it's style to plain so that it looks like a label not a button. However, i still have one problem (which isn't a major issue though but it's annoying me). when i run the app everything works fine but if i press on the item a white spot appears tracking my tapping gesture. how can i remove that? i searched the documentation and i couldn't find any thing related to recognizing gestures for items. help please ? or direct me to the documentation if i missed anything (i know you're not straightforward with your answers haha) thanks anyway.
     
  7. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #7
    The item should have an "enabled" property. Set it to false and it should stop tracking touches.
     
  8. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #8
    Glad you figured it out! :)
     
  9. hassoon thread starter macrumors regular

    Joined:
    Jun 8, 2009
    #9
    i tried that before but it fades into the background.i want it to still be there and clear but no recognition should be there. thanks.

    ----------

    :). any hints on the post that i posted earlier?
     
  10. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #10
    Don't use a UIBarButtonItem? :D
     
  11. hassoon thread starter macrumors regular

    Joined:
    Jun 8, 2009
    #11
    toolbars needs items. i can't add anything else besides the spaces
     
  12. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #12
    In code, you can add subviews.
     
  13. hassoon thread starter macrumors regular

    Joined:
    Jun 8, 2009
    #13
    Thanks it worked. i added a custom label by code then replaced the item with it. thanks man you're good :p
     
  14. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #14
    You replaced a UIBarButtonItem with a UILabel? How'd you manage that?

    You're welcome. And thank you for the compliment.
     
  15. hassoon thread starter macrumors regular

    Joined:
    Jun 8, 2009
    #15
    You're welcome! okay i'll be better than you, i'm not going to be beating around the bush (JK). here is the code:

    Code:
    SSCustomLabel *label = [[SSCustomLabel alloc] initWithFrame:CGRectMake(140 , 0, 50, 250)];
        label.text = [NSString stringWithFormat:@"%.2f", [self someMethod]];
        UIView *view = (UIView *) label;
        [self.barItem setCustomView:view];
    
    what i did is created a new class which is a subclass of UILabel (actually you don't have to do that but since i'll be customising the text font and colour and stuff, i made it that way just so my code looks cleaner). i then instantiated an object with a CGrect parameters. next put a text in it. then (the trick) assign the label casted as a UIView to an instant of UIView and after that use the setCustomView function to set the view over the item that you added in the interface builder. (barItem is a UIBarButtonItem)
     
  16. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #16
    Ah, so you didn't really replace a UIBarButtonItem with a UILabel. You just set the customView property of the item to the UILabel. Got it.
     
  17. hassoon thread starter macrumors regular

    Joined:
    Jun 8, 2009
    #17
    yup.
     

Share This Page