Draw dotted (not dashed!) line, with IBDesignable in 2017

前端 未结 10 1717
死守一世寂寞
死守一世寂寞 2020-11-28 03:25

It\'s easy to draw a dashed line with UIKit. So:

CGFloat dashes[] = {4, 2};
[path setLineDash:dashes count:2 phase:0];
[path stroke];
         


        
10条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-28 04:21

    Not a full answer, just a very important gotcha that James P raised in a comment on the favourite answer:

    He wrote:

    I've found setting the on length to 0.01 gives you a circular dot, whereas they are slightly elongated when using 0.

    For example,

       let dashes: [CGFloat] = [0.001, path.lineWidth * 2]
    

提交回复
热议问题