views:

38

answers:

1

Hi all,

I have subclassed UIView so I can draw some lines in it. In this UIView are a whole bunch of buttons which I decided to create as a method that drawRect calls after the lines are drawn. It works but sometimes only part of the button renders. If i remove the button creation and instead add the UIButton in the subclassed UIViews parent it works fine.

Is doing things like adding subviews in drawRect method a big no no or should I not do it all together in UIView?

+1  A: 

yea that's a pretty big no no. drawRect is for adding stuff with CG, not views. It gets called repeatedly and unpredictably. Adding them in initWithFrame should be pretty safe though.

Alex Gosselin
or initWithCoder if you are setting up the view in interface builder
skorulis