Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

lenix

macrumors newbie
Original poster
Jan 9, 2010
5
0
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
 
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.
 
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
 
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]);
 
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 :)
 
This should work:
Code:
[self setFrame:CGRectMake(x,y,width,height)];
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.