The
UIView
class defines a rectangular
area on the screen and the interfaces for managing the content in that
area. At runtime, a view object handles the rendering of any content in
its area and also handles any interactions with that content. The UIView
class itself provides basic behavior for filling its rectangular area
with a background color. More sophisticated content can be presented by
subclassing UIView
and implementing the necessary drawing
and event-handling code yourself. The UIKit framework also includes a
set of standard subclasses that range from simple buttons to complex
tables and can be used as-is. For example, a UILabel
object draws a text string and a UIImageView
object draws an image.
View drawing occurs on an as-needed basis. When a view is first
shown, or when all or part of it becomes visible due to layout changes,
the system asks the view to draw its contents. For views that contain
custom content using UIKit or Core Graphics, the system calls the
view’s
drawRect:
method. Your implementation of this method is responsible for drawing
the view’s content into the current graphics context, which is set up
by the system automatically prior to calling this method. This creates
a static visual representation of your view’s content that can then be
displayed on the screen.
Creating view programmatically:
CGRect viewRect = CGRectMake(10, 10, 100, 100);
UIView* myView = [[UIView alloc] initWithFrame:viewRect];
Important method in drawing the content on to the view:
drawRect: - Implement this method if your view draws custom content. If your view does not do any custom drawing, avoid overriding this method.
bounds: - The bounds rectangle, which describes the view’s location and size in its own coordinate system.
frame: - The frame rectangle, which describes the view’s location and size in its
superview’s coordinate system.
No comments:
Post a Comment