畫虛線

- (void)drawLine

{

UIView*lineView = [[UIViewalloc]init];

lineView.backgroundColor= [UIColorwhiteColor];

lineView.frame=CGRectMake(10,50,kScreenWidth-50,0.5);

[selfaddSubview:lineView];

CAShapeLayer*shapeLayer = [CAShapeLayerlayer];

[shapeLayersetBounds:lineView.bounds];

[shapeLayersetPosition:CGPointMake(CGRectGetWidth(lineView.frame) /2,CGRectGetHeight(lineView.frame))];

[shapeLayersetFillColor:[UIColorclearColor].CGColor];

//設(shè)置虛線顏色為blackColor

//[shapeLayer setStrokeColor:[UIColor colorWithRed:238.0/255.0 green:238.0/255.0 blue:238.0/255.0 alpha:1.0].CGColor];

[shapeLayersetStrokeColor:[UIColorlightGrayColor].CGColor];

//設(shè)置虛線寬度

[shapeLayersetLineWidth:CGRectGetHeight(lineView.frame)];

[shapeLayersetLineJoin:kCALineJoinRound];

//設(shè)置線寬,線間距

[shapeLayersetLineDashPattern:[NSArrayarrayWithObjects:[NSNumbernumberWithInt:3],[NSNumbernumberWithInt:1],nil]];

//設(shè)置路徑

CGMutablePathRefpath =CGPathCreateMutable();

CGPathMoveToPoint(path,NULL,0,0);

CGPathAddLineToPoint(path,NULL,CGRectGetWidth(lineView.frame),0);

[shapeLayersetPath:path];

CGPathRelease(path);

//把繪制好的虛線添加上來

[lineView.layer addSublayer:shapeLayer];

}


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 今天公司給了一個(gè)需求,要求畫上一段圓弧的虛線,說實(shí)話小弟不曾做過這個(gè),不過后來這個(gè)需求給別人做了,小弟心癢難耐,還...
    blink被沉默了閱讀 2,271評(píng)論 0 1
  • - (void)viewDidLoad { [super viewDidLoad]; [self getWeekD...
    MCWorld閱讀 436評(píng)論 0 0
  • 主要是講畫虛線,有個(gè)需求給按鈕添加虛線的邊框 一開始想到layer.border // 設(shè)置邊線 self.lay...
    許沐影閱讀 7,229評(píng)論 0 4
  • 在所需要的view上畫一條虛線,重寫下面的方法即可 -(void)drawRect:(CGRect)rect{ [...
    旅途開發(fā)者閱讀 470評(píng)論 2 0
  • 西藏當(dāng)兵前路艱,土資小兵上前線。 孫子兵法腦中顯,偉岸扛槍拉薩間。
    昊_2832閱讀 264評(píng)論 1 1

友情鏈接更多精彩內(nèi)容