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

krayziekray

macrumors 6502
Original poster
Sep 24, 2008
333
0
127.0.0.1
If I am coding an extension to UIView programatically, which function do I add all subviews in the View.m file in order to build the view hierarchy? The drawRect is definitely the wrong function to do this as this can be called hundreds of times and I don't believe the init functions would do this.

Thanks.
 

Ides

macrumors member
Mar 27, 2012
95
0
Not Understanding...

Could you please refrain your question? I can't really understand what you're trying to say. Something about the view hierarchy?

If you're asking about having the view properly display all of it's subviews, then the answer is: don't worry about it. The UIView class already has methods that will take care of the drawing of subviews, you don't need to write anything extra.
 

Sydde

macrumors 68030
Aug 17, 2009
2,552
7,050
IOKWARDI
Does your view itself have any special behavior or is it just a container for subviews? If it is just a container, you should not actually have to subclass UIView. Typically, subviews are added to a view by a view controller. The view takes care of the rest, and the subviews take care of themselves.
 

krayziekray

macrumors 6502
Original poster
Sep 24, 2008
333
0
127.0.0.1
Hi, so basically I want my view to add and position subviews when it is loaded rather than having to manually call a method to do so. Let's say my view is a container. When it is created I want it to add and position views depending on the values I added in the init function. Would layoutSubviews do this?

Thanks.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.