Since 6.5.2 起iOS地图SDK支持文字覆盖物(BMKText)绘制。
BMKText *_textOverlay = [BMKText textWithCenterCoordinate:CLLocationCoordinate2DMake(40.005, 116.554)text:@“天安门”];// 向地图View添加Overlay,需要实现BMKMapViewDelegate的-mapView:viewForOverlay:方法来生成标注对应的View[_mapView addOverlay:_textOverlay];
代码如下所示:
- (__kindof BMKOverlayView *)mapView:(BMKMapView *)mapView viewForOverlay:(id<BMKOverlay>)overlay {if ([overlay isEqual:_textOverlay]) {BMKTextView *textView = [[BMKTextView alloc] initWithTextOverlay:_textOverlay];textView.textColor = [UIColor redColor]; // 字体颜色textView.backgroundColor = [UIColor colorWithRed:0 green:1 blue:0 alpha:0.3]; // 背景色textView.fontSize = 12; // 字体大小textView.textFontType = kBMKTextFontNormal;textView.textAlignment = NSTextAlignmentCenter; // 文字对齐方式textView.textMaxLineWidth = 60; // 行宽textView.textLineSpacing = 0.f; // 行间距textView.textParagraphSpacing = 2; // 字符间距textView.textLineBreakMode = NSLineBreakByCharWrapping; // 字符截断类型return textView;}return nil;}
效果如下:
上一篇
下一篇
本篇文章对您是否有帮助?