IOS繪制虛線的方法,可以給cell設(shè)置虛線分割線

.h文件

@interface BaseLineView : UIView

@end

.m文件

@implementation BaseLineView
- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setBackgroundColor:[UIColor whiteColor]];
    }
    return self;
}
- (void)drawRect:(CGRect)rect {
   
    CGContextRef cont = UIGraphicsGetCurrentContext();
    CGContextSetStrokeColorWithColor(cont, [UIColor colorWithHexString:@"CFD3D2"].CGColor);
    // 設(shè)置線寬
    CGContextSetLineWidth(cont, 4);
    // lengths的值{3,3}表示先繪制3個(gè)點(diǎn),再跳過(guò)3個(gè)點(diǎn),如此反復(fù)
    CGFloat lengths[] = {3,3};
    CGContextSetLineDash(cont, 0, lengths, 2);  //畫(huà)虛線
    CGContextBeginPath(cont);
    CGContextMoveToPoint(cont, 0.0, rect.size.height - 1);    //開(kāi)始畫(huà)線
    CGContextAddLineToPoint(cont, kScreenW, rect.size.height - 1);
    CGContextStrokePath(cont);
}
@end
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容