Dotted line on map view

前端 未结 2 1635
时光说笑
时光说笑 2021-02-19 09:43

I can create a line between two points fairly easy with the below code (part of it anyways) How could I make the line dotted instead of solid? Also would it be possible to cha

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-19 09:44

    You can use the lineDashPattern property to create the pattern you want for the line.

    MKPolylineRenderer is a subclass of MKOverlayPathRenderer which has that property and a few others (see the link to the documentation).

    For example, this sets the pattern to a line 2 points long followed by a 5 point gap. The pattern is repeated for the entire length of the polyline.

    renderer.lineDashPattern = @[@2, @5];
    


    For the opacity, you can either apply an alpha to the strokeColor:

    renderer.strokeColor = [[UIColor orangeColor] colorWithAlphaComponent:0.5];
    

    or set the alpha property:

    renderer.alpha = 0.5;
    

    Not sure what you mean by "the longer the line is" part of the question.

提交回复
热议问题