Custom UIBarButtons

Discussion in 'iOS Programming' started by Boesesreh, Aug 11, 2009.

  1. Boesesreh macrumors newbie

    Joined:
    Aug 5, 2009
    #1
    I'm back with another question. I want my toolbar buttons to look like the one in the attachment. Is there an easy way of doing this or do i have to go through the whole custom view process. I don't even know how to this with custom view so a little help woul'd be really great
     

    Attached Files:

  2. AndyCodez macrumors regular

    Joined:
    Aug 6, 2009
    #2
    I have not played with this too much yet. Have you tried to use a round button and setting that image to that property? All I have done is change the background of a button and it seems to overwrite the original rect.
     
  3. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    No (not exactly) and No. Buttons like these can be achieved by setting the background image of a UIButton instance. See the UICatalog sample app for more help.
     
  4. Boesesreh thread starter macrumors newbie

    Joined:
    Aug 5, 2009
    #4
    Yeah i played around using the background image myself but i always endet up loosing the text i wanted to display. I looked at the catalog.app but i don't think this is going to help me because there are only buttons with only a image and i dont really want to create 100 images for that :D
     
  5. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    The first button example (createGrayButton) combines a background image and a text label ("Gray"). Look into that more closely and you won't need to create 100 images.
     
  6. Boesesreh thread starter macrumors newbie

    Joined:
    Aug 5, 2009
    #6
    Oh now that you say it. Is it possible to do this the same way for UIBarButtonItems or is there another way of doing this?
     
  7. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #7
    Ah, my apologies. I must've glossed over that you wanted UIBarButtonItems and not just regular UIButtons, even though it was right there in the thread title. How silly of me!

    So, UIBarButtonItem can be created with a UIBarButtonSystemItem, a custom view, an image or a title. Based on the button sample you attached to your OP, they seem to be using both an image (the arrow) and text ("Postpone (3)"). I'm not sure if this is possible by combining UIBarItem (UIBarButtonItem's superclass) properties of image and title; I kinda doubt it. (Don't give up on that possibility without investigtion.) I would suspect that a custom view may be required, however.
     
  8. Boesesreh thread starter macrumors newbie

    Joined:
    Aug 5, 2009
    #8
    It looks like a lot of work and I start thinking about forgetting the count in the braces and just make two images, one for enabled and another gray one for disabled. (Image = Image + text) I guess this would be the easiest way of doing this. Allthough it's sad that this feature isn't predefinded because the mail app includes it (yeaah the mail app again ^^) and I've seen it in at least one other app looking the exact same way

    Thanks again for the help
     

Share This Page