Create an iOS project in the OC-developed language, creating a new class inheritance with UIView
Rewrite the method and implement
//declare two instance variables inside the. h file{cgpoint _startpoint;//record the position when the click is slidingnsmutablearray* _marray;//record the position when sliding }//inside the. m file//overriding initialization methods-(ID) initWithFrame: (cgrect) frame{if(self==[Super Initwithframe:frame]) {Self.backgroundcolor=[uicolor Lightgraycolor];//set Background to gray_marray=[nsmutablearrayNew]; } returnSelf ;}//Touch Start Method-(void) Touchesbegan: (nsset*) touches withevent: (uievent*)Event{Uitouch* Touch = [touches anyobject];//gets a value that is arbitrary when clicked_startpoint = [Touch locationinview:self];//get the location when you clickNsmutablearray *pointarray = [NsmutablearrayNew];// //Convert to ObjectNsvalue *value =[Nsvalue Valuewithcgpoint:_startpoint]; //Saves the value of the clicked position to the newly created array[Pointarray Addobject:value]; [_marray Addobject:pointarray];}//How to slide the mouse-(void) touchesmoved: (nsset*) touches withevent: (uievent*)Event{ //similar to the Start method, just gets the last one of the _marray array and adds the obtained position to it.Nsmutablearray *pointarray =[_marray Lastobject]; Uitouch* touch=[touches anyobject]; Cgpoint Currentpoint=[Touch locationinview:self]; Nsvalue* value=[Nsvalue Valuewithcgpoint:currentpoint]; [Pointarray Addobject:value]; //This method echoes the painting method .[Self setneedsdisplay];//Show side Draw}//method At the end of the mouse-(void) touchesended: (nsset*) touches withevent: (uievent*)Event{}//Painting Method-(void) DrawRect: (cgrect) rect{cgcontextref CGRF= Uigraphicsgetcurrentcontext ();//Set Strokes//Thickness of strokeCgcontextsetlinewidth (CGRF,2.0f); //Color of strokesCgcontextsetstrokecolorwithcolor (Cgrf,[uicolor Yellowcolor]. Cgcolor); for(nsmutablearray* Pointarrinch_marray) { for(intI=0; i<pointarr.count-1; i++) {Nsvalue* value=Pointarr[i]; Cgpoint Apoint=[value cgpointvalue]; //move a brush to a specified pointCgcontextmovetopoint (CGRF, Apoint.x, APOINT.Y); Nsvalue* nextvalue=pointarr[i+1]; Cgpoint Nextapoint=[NextValue Cgpointvalue]; //wire The brush from the current point to the given point (for parameters of the function)Cgcontextaddlinetopoint (CGRF, Nextapoint.x, NEXTAPOINT.Y); }} cgcontextstrokepath (CGRF); }
Pay attention to implementing it in VIEWCONTROLLER.M.
Import #import "Draw.h"
-(void) viewdidload { [super Viewdidload]; // additional setup after loading the view, typically from a nib. self.view=[[Draw Alloc]initwithframe:[uiscreen mainscreen].bounds];}
I created draw, just need to change the custom file name to
So a simple artboard is done.
It's complicated. You can add controls on the artboard, change the brush color
IOS Learning Notes---One of the most basic artboards (pure Code implementation)