iOS application development: Small artboard Demo

Source: Internet
Author: User
Tags uikit

There are a lot of features can be added, note here to save slowly add it.

Code section

TouchView.h

#import <UIKit/UIKit.h>    
        
@interface touchview:uiview    
{    
    nsmutablearray *points;    
    Nsarray *points_all;    
    Cgcontextref context;    
    Uicolor *paint_clr;    
}    
@property (strong,nonatomic) Nsmutablearray *points;    
@property (strong,nonatomic) Nsarray *points_all;    
@property (strong,nonatomic) Uicolor *paint_clr;    
        
@end

touchview.m

#import "TouchView.h" @implementation Touchview @synthesize points, Points_all, PAINT_CLR;    
    -(ID) initWithFrame: (CGRect) frame {self = [super Initwithframe:frame];    
    if (self) {//initialization code PAINT_CLR = [Uicolor Greencolor];    
return self;    
//Only override Drawrect:if for you perform custom drawing.    
An empty implementation adversely affects performance during. -(void) DrawRect: (cgrect) Rect {//Drawing code if (!self.points) | | (Self.points.count < 2))    
    {return;    
    context = Uigraphicsgetcurrentcontext ();    
    Set Brush thickness cgcontextsetlinewidth (context, 5.0f);    
    Set the brush color//[[uicolor bluecolor]set];    
    [PAINT_CLR set];    
    Cgcontextsetstrokecolorwithcolor (context, [[Uicolor Bluecolor]cgcolor]); Cgcontextsetstrokecolorwithcolor (context, [PAINT_CLR Cgcolor]); Draw the previous trajectory for (int j = 0; J < [Self.points_all Count]; j +) {Nsmutablearray *points_tmp = [Points_    
                    
            All Objectatindex:j]; for (int i = 0;i < [points_tmp count]-1;i++) {cgpoint point1 = [[Points_tmp Object    
                ATINDEX:I] Cgpointvalue];    
                Cgpoint Point2 = [[Points_tmp objectatindex: (i+1)] cgpointvalue];    
                Cgcontextmovetopoint (context, point1.x, point1.y);    
                Cgcontextaddlinetopoint (context, point2.x, point2.y);    
            Cgcontextstrokepath (context); ///Draw this for (int i=0 i < [self.points count]-1; i++) {Cgpoint    
        Point1 = [[Self.points objectatindex:i] cgpointvalue];    
        Cgpoint Point2 = [[Self.points objectatindex: (i+1)] cgpointvalue];    
        Cgcontextmovetopoint (context, point1.x, point1.y); CgcontextAddlinetopoint (context, point2.x, point2.y);    
    Cgcontextstrokepath (context);    
Multi-point touch-(BOOL) ismultipletouchenabled {return no; //Create an array and record the initial ponit-(void) Touchesbegan: (Nsset *) touches withevent: (Uievent *) Event {s    
    Elf.points = [Nsmutablearray array];    
    Cgpoint pt = [[Touches anyobject] locationinview:self];    
[Self.points Addobject:[nsvalue valuewithcgpoint:pt]]; These points//call Setneedsdisplay are recorded in the//move process, triggering the invocation of the DrawRect Method-(void) touchesmoved: (Nsset *) touches withe    
    Vent: (Uievent *) event {Cgpoint pt = [[Touches anyobject] locationinview:self];    
    [Self.points Addobject:[nsvalue valuewithcgpoint:pt]];    
[Self setneedsdisplay]; }-(void) touchesended: (Nsset *) touches withevent: (Uievent *) event {Nsmutablearray = [    
    Nsmutablearray alloc] initWithArray:self.points]; if (Self.points_all = = Nil) {Self.points_all = [[Nsarray alloc] initwithobjects:points_tmp, nil];    
    }else {self.points_all = [Self.points_all arraybyaddingobject:points_tmp]; }} @end

Related Article

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.