I’m looking for a “canvas-like” element to use in iOS apps. By “canvas-like” I mean that I want a surface on which I can draw basic shapes such as rectangles, lines, text, or images. I do not need 3D or other really advanced stuff — rectangles and other images would be enough, text can be stored in images if required.
I can’t imagine that no such API is available, but how do they call it?
With UIKit, everything that the user sees and interacts with is essentially a view. For instance, a button is a view, a table view is a view, etc. Your application should already have a main view controller, or a main window, which can contain zero or more views. You can draw on any view that you create, as long as you are in the position to implement the
drawRect:method. Here’s an example of implementing aUIViewsubclass on which can you can draw using CoreGraphics:Then, in order to add an instance of
MyViewto your application, either drag in a custom view in interface builder and change its class toMyView, or do this inviewDidLoadof your view controller:You can learn more about what you can do in the
drawRectmethod from the Quartz 2D Programming Guide.