开发者

Subclassing UIView to draw in Quartz

开发者 https://www.devze.com 2023-04-04 23:58 出处:网络
I\'m trying to draw a figure in my iPhone application using Quartz 2D. I understand that I have to do t开发者_JAVA技巧his by subclassing UIView and overriding the drawRect function. I\'m trying to fol

I'm trying to draw a figure in my iPhone application using Quartz 2D. I understand that I have to do t开发者_JAVA技巧his by subclassing UIView and overriding the drawRect function. I'm trying to follow this tutorial to do this but I can't get it to work.

It seems subclassing UIView does not create a .xib-file like the tutorial seem to imply. Subclassing UIViewController (I know this is wrong but I tried it anyway) does create a .xib-file but does not seem to have the drawRect-function.

Has anyone any experience in this, or knows what I'm doing wrong?

Thank you in advance, Tobias Tovedal


  1. Create a UIView subclass and put your drawing code in its drawRect: method. You don't need a NIB file (why would you if you draw the view yourself?).

  2. In a view controller, create an instance of your custom view class, set the view's frame and add it to the view controller's view with: [self.view addSubview:myCustomView];.

  3. There is no step 3.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号