Label always two digits

Discussion in 'iPhone/iPad Programming' started by DIGITALiam, Jul 23, 2010.

  1. macrumors newbie

    Joined:
    Jun 23, 2010
    #1
    Hey I'm making a timer app that has both minutes and seconds. To do this I am using two different labels. How can I make sure it is always two digits (10:01 not 10:1).

    Thanks in advance.
     
  2. Moderator emeritus

    SilentPanda

    Joined:
    Oct 8, 2002
    Location:
    The Bamboo Forest
    #2
    If the number is less than 10 put a 0 in front of it. Just always convert the int to NSString and put it in the label that way.
     
  3. thread starter macrumors newbie

    Joined:
    Jun 23, 2010
    #3
    I thought of that too but it seems like there would be a more official way of doing it.
     
  4. Moderator emeritus

    SilentPanda

    Joined:
    Oct 8, 2002
    Location:
    The Bamboo Forest
    #4
    The only other reasonable way I can think of doing it would be to use a formatter. But admittedly I'm still working my way through the API so that might not be viable.
     
  5. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    What have you tried so far?
     
  6. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #6
  7. thread starter macrumors newbie

    Joined:
    Jun 23, 2010
    #7
    Thanks a lot that code works. I didn't get to reading through that page you linked to put the code did the trick. I'll use it even if I don't understand it.:rolleyes:
     
  8. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #8
    Bad idea. Copying-and-pasting is not programming.
     

Share This Page