Chapter 14. Graphics
The iOS SDK allows programmers to work with Quartz Core, which is encapsulated in the Core Graphics framework. In this chapter, we will use the Core Graphics framework extensively, so please make sure you have this framework added to your Xcode project by following these steps:
Find the Frameworks item in your Xcode project hierarchy and right-click on it.
Choose Add→Existing Frameworks.
Hold down the Command key and select the CoreGraphics.framework and QuartzCore.framework frameworks.
Click the Add button.
In this chapter, we will be using functions and methods available in the Core Graphics and Quartz Core frameworks. Quartz 2D is the engine in the Core Graphics framework that allows us to draw sophisticated shapes, paths, images, and so on.
Make sure you import both frameworks into your source files whenever needed, like so:
#import <QuartzCore/QuartzCore.h> #import <CoreGraphics/CoreGraphics.h>
Almost all the recipes in this chapter make use of the
drawRect: method of an instance of
UIView. This method gets called whenever a view has to be drawn.
The only parameter to this method is of type
CGRect, which tells you the rectangular area where you are
supposed to be doing your painting. Please refrain from painting anything
that is off this rectangle, as this will decrease the performance of your
To be able to use the code samples in these recipes, make sure you
UIView object by following
In Xcode, choose File