我正在UIButton用图像创建一个
我为此编写了以下代码:
let btnImg=UIButton.buttonWithType(UIButtonType.Custom) as UIButton
let img = UIImage(named: "turn_left") as UIImage
btnImg.setTitle("Turn left", forState: UIControlState.Normal)
btnImg.setImage(img, forState: UIControlState.Normal)
btnImg.frame = CGRectMake(10, 150, 200, 45)
self.view.addSubview(btnImg)
Run Code Online (Sandbox Code Playgroud)
但我得到以下错误let img = UIImage(named: "turn_left") as UIImage:
Swift Compiler error:
Downcast from 'UIImage?' to 'UIImage' only unwraps optionals; did you mean to use '!'?
Run Code Online (Sandbox Code Playgroud) 我的应用程序中有Map,根据用户位置移动.我已成功绘制了源和目标的折线.使用以下代码
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id < MKOverlay >)overlay{
MKPolylineView *view1 = [[MKPolylineView alloc] initWithOverlay:overlay];
view1.lineWidth = 27.0;
view1.strokeColor = [UIColor colorWithRed:55.0/255.0 green:168.0/255.0 blue:219.0/255.0 alpha:1];
return view1;
}
Run Code Online (Sandbox Code Playgroud)
但我的问题是当地图移动时,意味着我在用户移动时改变地图的区域,然后有时候折线显示不好,有时它的显示比实际尺寸更厚,如下图所示.
我正在附上下面的图片,请让我知道在地图移动时我可以为平滑折线做些什么.

编辑
正如Matt建议我创建一个MKPolylineRenderer的子类并实现drawMapRect方法,如下所示:
-(void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context{
CGMutablePathRef fullPath = CGPathCreateMutable();
BOOL pathIsEmpty = YES;
//merging all the points as entire path
for (int i=0;i< self.polyline.pointCount;i++){
CGPoint point = [self pointForMapPoint:self.polyline.points[i]];
if (pathIsEmpty){
CGPathMoveToPoint(fullPath, nil, point.x, point.y);
pathIsEmpty = NO;
} else {
CGPathAddLineToPoint(fullPath, nil, point.x, point.y);
}
}
//get …Run Code Online (Sandbox Code Playgroud) 在android地图应用程序中,它显示多条路线的工具提示窗口,谷歌地图也以同样的方式显示该窗口。我想知道这是自定义标记还是折线上的信息窗口。
有没有人知道如何通过 android map-v2 集成来实现这一目标?
下图显示了我对在 android 中实现的期望。
ios ×2
android ×1
google-maps ×1
infowindow ×1
mkmapview ×1
mkpolyline ×1
polyline ×1
swift ×1
uiimage ×1
xcode ×1