Ray's playground

 

Subclassing UIView(Chapter 6 of iOS Programming: The Big Nerd Ranch Guide)

Every UIView subclass implements the method drawRect:, which contains the drawing code for the view. For example, a UIButton’s drawRect: method draws a rounded rectangle with a title string in the center.
Each time an instance of UIView needs to be drawn (or redrawn), the system prepares a graphics context specifically for that view. Then the context is activated, and the message drawRect: is sent to the instance of UIView that is being drawn. The graphics context’s type is CGContextRef (Core Graphics Context Reference), and it is responsible for aggregating drawing commands and producing an image as a result. This image is the appearance of the view instance. A graphics context also stores its drawing state, which includes things like the current drawing color, coordinate system, and the current line width.
Every subview has a pointer back to its superview so that it can send its superview messages. The superview property of a UIView is set to its superview when the view is added to a view hierarchy.
(When a view is not part of a view hierarchy, superview is nil.) Superviews are not retained by their subviews.

 

posted on 2011-11-04 16:19  Ray Z  阅读(245)  评论(0编辑  收藏  举报

导航