CGContextSetLineDash(CGContextRef cg_nullable c, CGFloat phase, const CGFloat * __nullable lengths, size_t count)
- 設(shè)置虛線點的大小以及虛線點間隔大小的方法
參數(shù)
- c 上下文內(nèi)容
- lengths 傳入一個C語言的數(shù)組, 如下表示繪制1個點, 跳過10個點, 如此循環(huán)
// 部分代碼
CGFloat components[] = {1,10};
CGContextSetLineDash(context, 0, components, 2);

繪制1個點, 跳過10個點

繪制10個點, 跳過1個點
仔細看, 其實當數(shù)組傳入的是{0,10}, 0也是能看到一個很小的點的
- count 就是傳入lengths這個數(shù)組的長度, 如上面的components數(shù)組, count應(yīng)該傳入2, 如果count的數(shù)值和lengths數(shù)組的長度不一致, 每次生成的虛線
可能都不一樣 - phase 虛線相位, 第一個虛線繪制的時候跳過多少個點, 相當于向左移動了虛線, 如下代碼及結(jié)果(忽略截圖長度)
// 部分代碼
CGFloat components[] = {1,10};
CGContextSetLineDash(context, 0, components, 2);
CGFloat components[] = {1,10};
CGContextSetLineDash(context, 5, components, 2);
CGFloat components[] = {100,1};
CGContextSetLineDash(context, 0, components, 2);
CGFloat components[] = {100,1};
CGContextSetLineDash(context, 50, components, 2);



