如何更改GoogleMaps iOS中群集标记的标题颜色和大小?

问题描述:

在我的情况集群custome图像是白色的背景,我需要改变文本的颜色,使其更小如何更改GoogleMaps iOS中群集标记的标题颜色和大小?

- (void)configureMap { 
    // Set up the cluster manager with a supplied icon generator and renderer. 
    id<GMUClusterAlgorithm> algorithm = [[GMUNonHierarchicalDistanceBasedAlgorithm alloc] init]; 
    id<GMUClusterIconGenerator> iconGenerator = [self iconGeneratorWithImages]; 
    id<GMUClusterRenderer> renderer = [[GMUDefaultClusterRenderer alloc] initWithMapView:_mapView clusterIconGenerator:iconGenerator]; 

    _clusterManager = [[GMUClusterManager alloc] initWithMap:_mapView 
                algorithm:algorithm 
                renderer:renderer]; 
} 

- (id<GMUClusterIconGenerator>)iconGeneratorWithImages { 
    UIImage *clusterImage = [UIImage imageNamed:@"customClusterImage"]; 
    return [[GMUDefaultClusterIconGenerator alloc] initWithBuckets:@[@10, @50, @100, @200, @1000] 
                backgroundImages:@[clusterImage, clusterImage, clusterImage, clusterImage, clusterImage] 
                ]; 
} 

look at the pic

UPD:没有答案在这里:https://github.com/googlemaps/google-maps-ios-utils/issues/127

+0

网址:“https://googlemaps.github.io/js-marker-clusterer/images/m1.png”, width:53, height:53, fontFamily:“comic sans ms”, textSize:15, textColor:“red”, // color:#00FF00, }] –

+0

请查看[Marker Clustering]的文档(https://developers.google.com/maps/documentation/ios-sdk/utility/marker-clustering),请阅读“自定义标记群集”部分。 – Priyal

- (void)configureMapView { 

    // .... 

    id<GMUClusterAlgorithm> algorithm = [[GMUNonHierarchicalDistanceBasedAlgorithm alloc] init]; 
    id<GMUClusterIconGenerator> iconGenerator = [[GMUDefaultClusterIconGenerator alloc] init]; 
    GMUDefaultClusterRenderer *renderer = [[GMUDefaultClusterRenderer alloc] initWithMapView:_mapView clusterIconGenerator:iconGenerator]; 
    renderer.delegate = self; // <---- 1. set delegate 

    _clusterManager = [[GMUClusterManager alloc] initWithMap:_mapView 
                algorithm:algorithm 
                renderer:renderer]; 
} 

#pragma mark - <GMUClusterRendererDelegate> 

- (void)renderer:(id<GMUClusterRenderer>)renderer willRenderMarker:(GMSMarker *)marker { 

    if ([marker.userData isKindOfClass:[MyMarker class]]) { 

     marker.icon = [UIImage imageNamed:@"markerNormal"] // <----- 2.1 icon for ordinary marker 

    } else if ([marker.userData conformsToProtocol:@protocol(GMUCluster)]) { 

     // <------ 2.2 icon for cluster marker (draw title on image) 

     id<GMUCluster> userData = marker.userData; 
     marker.icon = [self drawFront:[UIImage imageNamed:@"markerGroup"] text:[NSString stringWithFormat:@"%@", @(userData.count)]]; 
    } 
} 

#pragma mark - 

- (UIImage *)drawFront:(UIImage *)image text:(NSString *)text { 

    // draw image first 
    UIGraphicsBeginImageContextWithOptions(image.size, false, [UIScreen mainScreen].scale); 
    [image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)]; 

    // text attributes 
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init]; 
    [style setAlignment:NSTextAlignmentCenter]; 

    NSDictionary *attr = @{NSParagraphStyleAttributeName : style, 
          NSFontAttributeName : [UIFont systemFontOfSize:17. weight:UIFontWeightRegular], // set text font 
          NSForegroundColorAttributeName : [UIColor redColor] // set text color 
          }; 

    const CGFloat paddingTop = 8.; 
    const CGRect rect = CGRectMake(0, paddingTop, image.size.width., image.size.height); 

    [text drawInRect:rect withAttributes:attr]; 

    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

    return newImage; 
}