iOS開發畫虛線的方法

2022-08-12 13:54:29 字數 1371 閱讀 7733

cashapelayer *shapelayer = [cashapelayer layer];

[shapelayer setbounds:self.view.bounds];

[shapelayer setposition:self.view.center];

[shapelayer setfillcolor:[[uicolor clearcolor] cgcolor]];

// 設定虛線顏色為blackcolor

[shapelayer setstrokecolor:[[uicolor blackcolor] cgcolor]];

[shapelayer setstrokecolor:[[uicolor colorwithred:223/255.0 green:223/255.0 blue:223/255.0 alpha:1.0f] cgcolor]];

// 3.0f設定虛線的寬度

[shapelayer setlinewidth:1.0f];

[shapelayer setlinejoin:kcalinejoinround];

// 3=線的寬度 1=每條線的間距

[shapelayer setlinedashpattern:

[nsarray arraywithobjects:[nsnumber numberwithint:3],

[nsnumber numberwithint:1],nil]];

// setup the path

cgmutablepathref path = cgpathcreatemutable();

cgpathmovetopoint(path, null, 0, 89);

cgpathaddlinetopoint(path, null, 320,89);

// setup the path

cgmutablepathref path1 = cgpathcreatemutable();

// 0,10代表初始座標的x,y

// 320,10代表初始座標的x,y

cgpathmovetopoint(path1, null, 0, 100);

cgpathaddlinetopoint(path1, null, 320,100);

[shapelayer setpath:path];

cgpathrelease(path1);

// 可以把self改成任何你想要的uiview, 下圖演示就是放到uitableviewcell中的

android開發 畫虛線

public class dashview extends view public dashview context context,attributeset attrs override protected void onmeasure int widthmeasurespec,int heigh...

iOS 開發之繪製虛線

pragma mark 繪製虛線具體方法 lineview 需要繪製成虛線的view linelength 虛線的寬度 linespacing 虛線的間距 linecolor 虛線的顏色 void drawdashline uiview lineview linelength nsinteger l...

iOS 使用Quartz 2D畫虛線

畫虛線需要用到函式 cgcontextsetlinedash 此函式需要四個引數 cpp view plain copy print cgcontextref context uigraphicsgetcurrentcontext cgcontextbeginpath context cgconte...