1.重寫drawRect方法
- (void)drawRect:(CGRect)rect{
CGContextRef currentContext = UIGraphicsGetCurrentContext();
//設(shè)置虛線顏色
CGContextSetStrokeColorWithColor(currentContext, [YSCUiUtils colorTwo].CGColor);
//設(shè)置虛線寬度
CGContextSetLineWidth(currentContext, 1);
//設(shè)置虛線繪制起點
CGContextMoveToPoint(currentContext, 0, 50);
//設(shè)置虛線繪制終點
CGContextAddLineToPoint(currentContext, SCREEN_WIDTH, 50);
//設(shè)置虛線排列的寬度間隔:下面的arr中的數(shù)字表示先繪制3個點再繪制1個點
CGFloat arr[] = {6,3};
//下面最后一個參數(shù)“2”代表排列的個數(shù)。
CGContextSetLineDash(currentContext, 0, arr, 4);
CGContextDrawPath(currentContext, kCGPathStroke);
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者