1 Preface
From today on, we start to learn about IOS graphics and animation.
In Cocoa Touch, a program consists of a window and a view. A program with a UI has at least one window, which contains at least one or more views. In Cocoa Touch, a window is an instance of a UIWindow. Generally, the program opens to the main window, And the programmer adds a View to the window to display different parts of the UI, such as buttons, text, images, and custom controls. All these UI-related components are processed and drawn by UIKit.
Apple provides developers with a powerful framework to process graphics and animations in iOS and OS X. The following are the frameworks and technologies:
UIKit
A high-level framework allows programmers to create views, windows, buttons, and other UI-related controls. It also combines low-layer APIs into an easy-to-use high-level API.
Quartz 2D
Run the internal main engine used for iOS drawing; UIKit uses Quarz.
Core Graphics
Supports the graphic environment (which will be introduced later), loading images, and drawing images.
Core Animation
As the name implies, an animation frame on iOS.
Today, let's briefly learn how to draw text on iOS devices.
2. code example
ZYViewControllerView. m
[Plain]
-(Void) drawRect :( CGRect) rect {
// Set the Font Style
UIFont * helveticaBold = [UIFont fontWithName: @ "HelveticaNeue-Bold" size: 30366f];
/* Load the color */
UIColor * magentaColor = [UIColor colorWithRed: 0.5f
Green: 0.0f blue: 0.5f
Alpha: 1.0f];
/* Set the color in the graphical context */
[MagentaColor set];
// Text content
NSString * myString = @ "I Learn Really Fast ";
// Draw a simple string at 30 o'clock in the 25 and y axes 190 of the x axis on the screen
// [MyString drawAtPoint: CGPointMake (25,190) withFont: helveticaBold];
[MyString drawInRect: CGRectMake (100,/* x */
120,/* y */
100,/* width */
200)/* height */
WithFont: helveticaBold];
// Obtain a color for 2D Z 2D plotting. Read-Only
CGColorRef colorRef = [magentaColor CGColor];
// Returns the color component.
Const CGFloat * components = CGColorGetComponents (colorRef );
// Returns the number of color components.
NSUInteger componentsCount = CGColorGetNumberOfComponents (colorRef );
NSUInteger counter = 0;
For (counter = 0; counter <componentsCount; counter ++) {// loop output
NSLog (@ "Component % lu = %. 02f", (unsigned long) counter, components [counter]);
}
}
-(Void) drawRect :( CGRect) rect {
// Set the Font Style
UIFont * helveticaBold = [UIFont fontWithName: @ "HelveticaNeue-Bold" size: 30366f];
/* Load the color */
UIColor * magentaColor = [UIColor colorWithRed: 0.5f
Green: 0.0f blue: 0.5f
Alpha: 1.0f];
/* Set the color in the graphical context */
[MagentaColor set];
// Text content
NSString * myString = @ "I Learn Really Fast ";
// Draw a simple string at 30 o'clock in the 25 and y axes 190 of the x axis on the screen
// [MyString drawAtPoint: CGPointMake (25,190) withFont: helveticaBold];
[MyString drawInRect: CGRectMake (100,/* x */
120,/* y */
100,/* width */
200)/* height */
WithFont: helveticaBold];
// Obtain a color for 2D Z 2D plotting. Read-Only
CGColorRef colorRef = [magentaColor CGColor];
// Returns the color component.
Const CGFloat * components = CGColorGetComponents (colorRef );
// Returns the number of color components.
NSUInteger componentsCount = CGColorGetNumberOfComponents (colorRef );
NSUInteger counter = 0;
For (counter = 0; counter <componentsCount; counter ++) {// loop output
NSLog (@ "Component % lu = %. 02f", (unsigned long) counter, components [counter]);
}
}
Engineering
Note: You must set the class of the view in the nib file to ZYViewControllerView.
Running result
Console display
11:14:13. 611 GraphicsStringTest [1030: c07] Component 0 = 0.50
11:14:13. 613 GraphicsStringTest [1030: c07] Component 1 = 0.00
11:14:13. 614 GraphicsStringTest [1030: c07] Component 2 = 0.50
11:14:13. 615 GraphicsStringTest [1030: c07] Component 3 = 1.00