ios - how to create Start and end point straight line using objective c -


can please tell me, how add starting point end point straight line. , have added button drag same line tough end point call method. please tell me need code.

there 2 common techniques.

using cashapelayer:

create uibezierpath (replace coordinates whatever want):

 uibezierpath *path = [uibezierpath bezierpath];  [path movetopoint:cgpointmake(10.0, 10.0)];  [path addlinetopoint:cgpointmake(100.0, 100.0)]; 

create cashapelayer uses uibezierpath:

cashapelayer *shapelayer = [cashapelayer layer]; shapelayer.path = [path cgpath]; shapelayer.strokecolor = [[uicolor bluecolor] cgcolor]; shapelayer.linewidth = 3.0; shapelayer.fillcolor = [[uicolor clearcolor] cgcolor]; 

add cashapelayer view's layer:

[self.view.layer addsublayer:shapelayer]; 

in previous versions of xcode, had manually add quartzcore.framework project's "link binary libraries" , import header in .m file, that's not necessary anymore (if have "enable modules" , "link frameworks automatically" build settings turned on).

the other approach subclass uiview , use coregraphics calls in drawrect method:

create uiview subclass , define drawrect draws line:

- (void)drawrect:(cgrect)rect {     cgcontextref context = uigraphicsgetcurrentcontext();      cgcontextsetstrokecolorwithcolor(context, [[uicolor bluecolor] cgcolor]);     cgcontextsetlinewidth(context, 3.0);     cgcontextmovetopoint(context, 10.0, 10.0);     cgcontextaddlinetopoint(context, 100.0, 100.0);     cgcontextdrawpath(context, kcgpathstroke); } 

then can either use view class base class nib/storyboard or view, or can have view controller programmatically add subview:

customview *view = [[customview alloc]     initwithframe:self.view.bounds]; view.backgroundcolor = [uicolor clearcolor];  [self.view addsubview:view]; 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -