Earliest access to bounds from UIView

Discussion in 'iOS Programming' started by darkandlong, Sep 6, 2011.

  1. darkandlong macrumors member

    darkandlong

    Joined:
    Jun 19, 2008
    Location:
    Uk
    #1
    Hi,

    I need to set a property of a UIView (from inside the same UIView, not from its ViewController) based on its initial bounds. What is the earliest point I can access its bounds?

    I have tried:

    and

    but in both cased self.bounds is still null.

    Thanks.
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    I believe viewWillAppear: is the earliest (although I might be wrong).
     
  3. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #3
    It's about the earliest I'd consider the values to be worth trusting.
     
  4. darkandlong thread starter macrumors member

    darkandlong

    Joined:
    Jun 19, 2008
    Location:
    Uk
    #4
    Thanks for your replies.

    turns out bounds were available as early as initWithCoder. Problem was I was trying to NSLog the bounds which are a struct and so they were printing as null even though they were there.
     
  5. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    I'd suggest taking advantage of the NSStringFromCGRect() function.
     
  6. ppilone macrumors 6502

    Joined:
    Jan 20, 2008
    #6
    I'd be careful about using the bounds of any view before viewWillAppear. It seems like any time before that method is called the bounds may or may not have had the correct rotation transform applied.
     

Share This Page