IOS Drawing Basics

Source: Internet
Author: User

Basic points:

1, paint can not be in the Viewcontroller, but should be in a UIView subclass, such as a new drawview inherit from UIView.

2, covering UIView's DrawRect method, makes it to draw the graph that conforms to the need.

#import<UIKit/UIKit.h>@interfaceDrawview:uiview@end/*****************************/#import "DrawView.h"@implementationDrawviewStatic intHeight =0;- (void) DrawRect: (cgrect) rect{NSLog (@"DrawRect"); Height= height +Ten; CGRect bounds=[self bounds]; [[Uicolor Yellowcolor]Set];    Uirectfill (bounds); CGRect Square= CGRectMake ( -, -, -, height); [[Uicolor Greencolor]Set];    Uirectfill (square); [[Uicolor Blackcolor]Set]; Uirectframe (square);}@end

3, drawing is automatically called by an object call to Drawview ([view setneedsdisplay];) to draw drawrect. View needs to be a Drawview object.

-(Ibaction) Drawview: (ID) sender{    NSLog (@ "drawview");    [View Setneedsdisplay];}

4, note that there are several situations where drawrect is not called:

(1) When the size of the view frame is (0,0), the system does not execute the DrawRect method.

(2) When this view is not Superview (view is the outermost UIView), it will still not execute DrawRect

Additional note: When View.hidden=yes or view.frame out of bounds, the DrawRect method is still called, which shows that there are two cases where the DrawRect method is not executed.

IOS Drawing Basics

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.