gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:31:54 24 4
gpt4 key购买 nike

在我的例子中,集群客户图像是白色背景,我需要更改文本的颜色并使其更小

- (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

最佳答案

- (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;
}

关于ios - 如何更改 GoogleMaps iOS 中群集标记标题的颜色和大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46033829/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com