Search code examples
ioscocoa-touchuikitcore-graphics

Draw custom CGContextRef - bigger than frame?


I have the frame of my UIView, and in drawRect it uses this as the context, but I want it to draw outside of this context. How do I specify my own context, to get it to do so?


Solution

  • I don't understand how you use a frame as a context. A frame is a CGRect and a context is a CGContextRef.

    Maybe you are asking whether the drawing commands in your drawRect: method can affect pixels on the screen that are outside of the view's bounds. The answer is no. You could create a CALayer that is a child of your view's layer and has a frame that extends outside of your view's bounds. If your view doesn't clip subviews, then that layer can draw outside of your view's bounds. You need to read about Core Animation or watch the WWDC videos to learn more about this.

    Maybe you are asking how to create an off-screen bitmap that is larger than your UIView's bounds, and draw to that bitmap. If that is what you want to do, then look at Drawing to a Bitmap Graphics Context in the Drawing and Printing Guide for iOS.