IOS 设置百度地图自定义标注图片,自定义泡泡
发布时间:2020-12-16 07:42:39 所属栏目:百科 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 #pragma mark - BMKMapViewDelegate// 根据anntation生成对应的View- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id BM
以下代码由PHP站长网 52php.cn收集自互联网 现在PHP站长网小编把它分享给大家,仅供参考 #pragma mark - BMKMapViewDelegate // 根据anntation生成对应的View - (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation { //普通annotation NSString *AnnotationViewID = @"ClusterMark"; ClusterAnnotation *cluster = (ClusterAnnotation*)annotation; ClusterAnnotationView *annotationView = [[ClusterAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID]; annotationView.size = cluster.size; annotationView.canShowCallout = NO;//在点击大头针的时候会弹出那个黑框框 annotationView.draggable = NO;//禁止标注在地图上拖动 annotationView.annotation = cluster; // annotationView.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:annotation.subtitle]]]; annotationView.centerOffset=CGPointMake(0,0); UIView *viewForImage=[[UIView alloc]initWithFrame:CGRectMake(0,110,110)]; UIImageView *imageview=[[UIImageView alloc]initWithFrame:CGRectMake(0,110)]; [imageview setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:annotation.subtitle]]]]; imageview.layer.masksToBounds=YES; imageview.layer.cornerRadius = 10; [viewForImage addSubview:imageview]; annotationView.image=[self getImageFromView:viewForImage]; return annotationView; } -(UIImage *)getImageFromView:(UIView *)view{ UIGraphicsBeginImageContext(view.bounds.size); [view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; } //气泡框左侧显示的View,可自定义 annotationView.leftCalloutAccessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_location.png"]]; //气泡框右侧显示的View 可自定义 annotationView.rightCalloutAccessoryView =selectButton; //让标注在进入界面时就处于弹出气泡框的状态 [annotationView setSelected:YES animated:YES]; 以上内容由PHP站长网【52php.cn】收集整理供大家参考研究 如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |