地图视图上的虚线 [英] Dotted line on map view

查看:402
本文介绍了地图视图上的虚线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用下面的代码(相反部分)在两点之间创建一条线,我怎样才能使线条点缀而不是实线?也可以更改不透明度线越长?

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 change the opacity the longer the line is?

- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id < MKOverlay >)overlay
{
    MKPolylineRenderer *renderer =[[MKPolylineRenderer alloc] initWithPolyline:overlay];
    renderer.strokeColor = [UIColor orangeColor];
    renderer.lineWidth = 3.0;

    return renderer;
}


推荐答案

你可以使用 lineDashPattern 属性,用于为该行创建所需的模式。

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

MKPolylineRenderer MKOverlayPathRenderer 的子类,其中包含财产和其他一些(见文件的链接)。

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

例如,这会将模式设置为2点长的行,然后是5点间隙。在折线的整个长度上重复该模式。

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];



对于不透明度,您可以将alpha应用于 strokeColor

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

或设置 alpha 属性:

renderer.alpha = 0.5;

不确定你的意思是线越长是问题的一部分。

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

这篇关于地图视图上的虚线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆