sizeToFit() for UILabel is moving left.

Discussion in 'iOS Programming' started by Narendar Singh, Jul 10, 2012.

  1. Narendar Singh macrumors member

    Narendar Singh

    Joined:
    Jun 22, 2012
    Location:
    INDIA
    #1
    Please see attached image for the reference, I have a problem with sizeToFit() function in UILable.
     

    Attached Files:

  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    The origin of the coordinate system is on the left. The position of any view is based on the left (for the x component of position) Size to fit changes the size but not the position of the component. So the behaviour is exactly what you should expect: position unchanged and size changed.

    For sizeToFit: to do what you are expecting it would have to change the position as well as the size.
     
  3. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
  4. Narendar Singh thread starter macrumors member

    Narendar Singh

    Joined:
    Jun 22, 2012
    Location:
    INDIA
    #4
    Yes I want to change position too. What should I do now?

    dejo: I'll update soon.
     
  5. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #5
    Calculate the correct position based on the new size and change the origin to that.
     
  6. Narendar Singh thread starter macrumors member

    Narendar Singh

    Joined:
    Jun 22, 2012
    Location:
    INDIA
    #6
    make sense, thanks.
     
  7. Narendar Singh thread starter macrumors member

    Narendar Singh

    Joined:
    Jun 22, 2012
    Location:
    INDIA
    #7
    How can I do that?

    In Xcode 4:

    Xcode -> Preferences -> Downloads -> Components -> Check and Install Now saying "No updates available"
     
  8. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #8
    Do you have Xcode 4.5 DP? Also, be aware that auto-layout will only work in apps targeted for iOS 6+.
     
  9. Narendar Singh thread starter macrumors member

    Narendar Singh

    Joined:
    Jun 22, 2012
    Location:
    INDIA
    #9
    NO, I have Xcode 4.3.1
     
  10. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #10
    In order to use Auto Layout, one of the "tent pole" features of iOS 6, you'll need to use Xcode 4.5.
     
  11. Narendar Singh thread starter macrumors member

    Narendar Singh

    Joined:
    Jun 22, 2012
    Location:
    INDIA
    #11
    make sense... well my problem is solved using some run time calculation. thanks
     

Share This Page