2016-12-02 93 views
3

我以前this example借鑑uiview虛線:更改虛線厚度在IOS

UIBezierPath *path = [UIBezierPath bezierPath]; 
//draw a line 
[path moveToPoint:yourStartPoint]; //add yourStartPoint here 
[path addLineToPoint:yourEndPoint];// add yourEndPoint here 
[path stroke]; 

float dashPattern[] = {1,1,1,1}; //make your pattern here 
[path setLineDash:dashPattern count:4 phase:0]; 

UIColor *fill = [UIColor blueColor]; 
shapelayer.strokeStart = 0.0; 
shapelayer.strokeColor = fill.CGColor; 
shapelayer.lineWidth = 7.0; 
shapelayer.lineJoin = kCALineJoinMiter; 
shapelayer.lineDashPattern = [NSArray arrayWithObjects:[NSNumber numberWithInt:10],[NSNumber numberWithInt:10], nil]; 
shapelayer.lineDashPhase = 3.0f; 
shapelayer.path = path.CGPath; 

它的工作原理,但問題是,即使我把我的uiview身高1,我得到的線頗濃。 enter image description here

是否有可能使它更薄?

回答

3

你可以在這部分代碼改變線條的粗細:

shapelayer.lineWidth = 7.0; 

更改7.0到任何厚度你想你的線有。

+0

WTF:/爲什麼地獄名爲lineWIDTH的屬性改變了它的高度? :( 無論如何,非常感謝:| – arsena

+1

,因爲'線'有寬度不高度,英語;;) –

+0

'lineThickness'會有道理 – RJR