1+ (void) Drawdashline: (UIView *) Lineview linelength: (int) LineLength linespacing: (int) linespacing LineColor: (Uicolor *) LineColor2 {3Cashapelayer *shapelayer =[Cashapelayer layer];4 [Shapelayer setBounds:lineView.bounds];5[Shapelayer Setposition:cgpointmake (Cgrectgetwidth (lineview.frame)/2, Cgrectgetheight (Lineview.frame))];6 [Shapelayer Setfillcolor:[uicolor Clearcolor]. Cgcolor];7 //Set Dash color8 [Shapelayer SetStrokeColor:lineColor.CGColor]; 9 //set the dash widthTen [Shapelayer setlinewidth:cgrectgetheight (Lineview.frame)]; One [Shapelayer Setlinejoin:kcalinejoinround]; A //Set line width, line spacing - [Shapelayer setlinedashpattern:[nsarray arraywithobjects:[nsnumber numberwithint:linelength], [NSNumber Numberwithint:linespacing], nil]]; - //Set Path theCgmutablepathref Path =cgpathcreatemutable (); -Cgpathmovetopoint (Path, NULL,0,0); -Cgpathaddlinetopoint (Path, NULL, Cgrectgetwidth (Lineview.frame),0); - [Shapelayer Setpath:path]; + cgpathrelease (path); - //Add the drawn dashed line + [Lineview.layer Addsublayer:shapelayer]; A}
Draw a dashed line