Search code examples
ioscalayerdrawrect

Setting the CALayer bounds and position from a view controller


  1. I have one set of view controller(.h, .m and .XIB)
  2. I have one set of view(.h&.m)

3.The view class is responsible for drawing gauge using -->drawRect -->CALayer and sublayers In this view I have initialize method, and this method only i set the bounds for my layers and sublayers

In my view controller, I have created 5 views in my xib and .h and i am assigning the same view class for all the 5 views.

Now the problem is, all 5 views differ in their position and bounds. But my drawRect view class has only one set of bounds for all views. So if I hardcode the bounds and position in initialize method with respect to one view, the remaining 4 views are getting affected. Please let me know if u know where iam going wrong.


Solution

  • The +initialize method is a static method, meaning it affects all instances of that class. Use the -init method (or a custom -init method) to set different bounds for your views.

    At least I hope I understand your question correctly. Please post some code if this doesn't help