1
我想在UIView中畫一些虛線,但我不知道我是否正確地做。第一個破折號與其他破折號相比有一半的寬度。快速越來越奇怪的溺水虛線
代碼:
let strokeColor = UIColor.white.cgColor
let path = UIBezierPath()
path2.move(to: CGPoint(x: 0, y: 50))
path2.addLine(to: CGPoint(x: 340, y: 50))
//thickHorizontalLayer.frame = frame
thickHorizontalLayer.path = path.cgPath
thickHorizontalLayer.strokeColor = strokeColor
thickHorizontalLayer.lineWidth = 15
thickHorizontalLayer.fillColor = UIColor.clear.cgColor
thickHorizontalLayer.lineDashPattern = [ 0.5, 6 ]
thickHorizontalLayer.lineDashPhase = 0.25
self.layer.addSublayer(thickHorizontalLayer)
是什麼它吸引:http://imgur.com/a/2NuRE
這是做的最好的方法是什麼? 如果你看到,第一個破折號是比其他人... ...
加問題:我怎麼能得到的UIView的約束的y值?例如bound = 340,這是上面的情況。
編輯:
我想抽2種破折號模式(一個細小的等厚),但它變得混亂...:
fileprivate let thickHorizontalLayer = CAShapeLayer()
fileprivate let thinHorizontalLayer = CAShapeLayer()
let strokeColor = UIColor.white.cgColor
let path2 = UIBezierPath()
path2.move(to: CGPoint(x: 20, y: 50))
path2.addLine(to: CGPoint(x: 320, y: 50))
//thickHorizontalLayer.frame = frame
thickHorizontalLayer.path = path2.cgPath
thickHorizontalLayer.strokeColor = strokeColor
thickHorizontalLayer.lineWidth = 20
thickHorizontalLayer.fillColor = UIColor.clear.cgColor
thickHorizontalLayer.lineDashPattern = [ 1, 73.5 ]
//thickHorizontalLayer.lineDashPhase = 0.25
self.layer.addSublayer(thickHorizontalLayer)
let path3 = UIBezierPath()
path3.move(to: CGPoint(x: 0, y: 52.5))
path3.addLine(to: CGPoint(x: 340.0, y: 52.5))
//thinHorizontalLayer.frame = frame
thinHorizontalLayer.path = path3.cgPath
thinHorizontalLayer.strokeColor = strokeColor
thinHorizontalLayer.lineWidth = 15.0
thinHorizontalLayer.fillColor = UIColor.clear.cgColor
thinHorizontalLayer.lineDashPattern = [ 0.5, 6.25 ]
//thinHorizontalLayer.lineDashPhase = 0.25
self.layer.addSublayer(thinHorizontalLayer)
如果仔細觀察,可以看出它變得很奇怪(看破折號的顏色)::http://imgur.com/YlVJ7mn
我想從x中畫出5個破折號: 20到x:320,並且在它們之間(但是在x:0到x:340之間)畫出9條更細的破折號。希望有人能幫我解決這個...
你明確要求虛線相位中途開始進入第一個衝刺。 – Ssswift
@Ssswift我不再使用DashPhase,但我仍然很困惑這一切。我試圖畫出2個短劃線,一個很薄,另一個很厚......我將編輯這個問題以顯示更多內容。 –
如果你想要的厚度是厚壁蜱的10倍,那麼這些破折號應該覆蓋距離的1/10,否?但6.75並不是74.5的任何整數倍數。 – Ssswift