Connecting UIView outlet to the view itslef?

Discussion in 'iOS Programming' started by lenix, Jan 9, 2010.

  1. lenix macrumors newbie

    Joined:
    Jan 9, 2010
    #1
    Hello,

    I'd really appreciate some help on this, here is what I've done so far:

    1) Created a window-based application
    2) Added a UIView subclass ( UICustom.m + UICustom.h )
    3) declared an outlet in .h ( IBOutlet UIView *view; )
    4) Launch IB, add a view to Main Window.
    5) Associated this view with UICustom ( using inspector )

    Now I'm trying to connect the outlet 'view' to the view I added using IB.
    But sadly, I can't, whatever I tried.

    Does the logic fail here or I'm doing something wrong?

    Note: I Want to connect the outlet with the view so I can get the values of width + height of the view.

    I hope I explained myself fine. Thanks in advance
     
  2. drf1229 macrumors regular

    drf1229

    Joined:
    Jun 22, 2009
    #2
    I don't see why you're doing it that way. If you want to create a class attached to a view, just click File>Write Class Files in interface builder while you have the view you want selected. Before this, you might want to click on the view, then go to the last tab in inspector and type in a name.
     
  3. lenix thread starter macrumors newbie

    Joined:
    Jan 9, 2010
    #3
    Thanks for the reply mate, but it didn't help.

    I'm going to rephrase the question:

    Let's say you add a UIView subclass, you associate a view to that subclass ( using inspector ).. How can I retrieve the width\height of the view using code?

    I'm doing this because I want to do some dynamic layout according to the size of the view.

    I know it's achievable if I create the UIView using code ( instead of IB ) but I'm not gonna resort to that until a while.. hoping for a solution.

    Please help, I'm new to objective-c.

    Many thanks in advance
     
  4. drf1229 macrumors regular

    drf1229

    Joined:
    Jun 22, 2009
    #4
    Ok I see...Didn't completely understand what you were asking sorry!
    This should work:
    Code:
    float height=CGRectGetHeight([self frame]);
    float width=CGRectGetWidth([self frame]);
     
  5. lenix thread starter macrumors newbie

    Joined:
    Jan 9, 2010
    #5
    Thanks man, it works <3

    Another question if you don't mind though... Now I know how to retrieve the view width/height, is there a way to set those values by using code?

    I tried something like:
    Code:
    CGSize testSize;
    testSize.height = 55;
    testSize.width = 200;
    self.bounds.size = testSize;
    
    But it won't work.. anyways cheers and thanks a lot :)
     
  6. drf1229 macrumors regular

    drf1229

    Joined:
    Jun 22, 2009
    #6
    This should work:
    Code:
    [self setFrame:CGRectMake(x,y,width,height)];
     
  7. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #7
    You could also use:
    Code:
    float height = self.frame.size.height;
    float width = self.frame.size.width;
     

Share This Page