tags:

views:

424

answers:

2

Hello guys,

I have a UIViewController in which I want to draw a square. So do I need to create a UIView for that and add the created view to my viewControllers view.

Like Is there any way to do that or can I override the drawRect: method for my controllers view to draw that square.

A: 

Draw rect draws the rectangle which becomes the views frame, you can draw the Square in viewDidLoad tho

Daniel
A: 

A view controller owns, but is not, a view. Add a view to the self.view of the view controller. Add your view in or after viewDidLoad is called in the controller.

For the specific case of a filled square or rectangle there is no need to draw anything. Just set the background color and frame of the new view.

drawnonward