用UIKit 绘制虚线很容易.所以:
CGFloat dashes[] = {4, 2};
[path setLineDash:dashes count:2 phase:0];
[path stroke];
Run Code Online (Sandbox Code Playgroud)

有没有办法画出真正的虚线?

有任何想法吗?
由于这个问题很老,没有人提出完整的@IBDesignable解决方案,这里是...
希望能节省一些打字的人.
@IBDesignable class DottedVertical: UIView {
@IBInspectable var dotColor: UIColor = UIColor.etc
@IBInspectable var lowerHalfOnly: Bool = false
override func draw(_ rect: CGRect) {
// say you want 8 dots, with perfect fenceposting:
let totalCount = 8 + 8 - 1
let fullHeight = bounds.size.height
let width = bounds.size.width
let itemLength = fullHeight / CGFloat(totalCount)
let path = UIBezierPath()
let …Run Code Online (Sandbox Code Playgroud)