gpt4 book ai didi

iphone - 如何绘制填充颜色不是纯色而是图像的 MKCircle

转载 作者:太空狗 更新时间:2023-10-30 03:25:17 24 4
gpt4 key购买 nike

我找到了如何在 map 注释周围画一个圆圈。我这样做:

     MKCircle *circle = [MKCircle circleWithCenterCoordinate:theCoordinate radius:15000];
[myMap addOverlay:circle];

-(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id)overlay
{
MKCircleView *circleView = [[MKCircleView alloc] initWithOverlay:overlay];
circleView.fillColor =[UIColor redColor];

return circleView;
}

它工作正常,但我想画一个填充颜色不是这样的圆:

enter image description here

最佳答案

使用 MKCircleRenderer 回答 iOS 7...

您应该将 MKCircleRenderer 子类化,并覆盖 fillPath:inContext 方法,类似于该问题的已接受答案。例如

@implementation MKGradientCircleRenderer

- (void)fillPath:(CGPathRef)path inContext:(CGContextRef)context
{

CGRect rect = CGPathGetBoundingBox(path);

CGContextAddPath(context, path);
CGContextClip(context);

CGFloat gradientLocations[2] = {0.6f, 1.0f};
// Start color white with 0.25 alpha,
// End color green with 0.25 alpha
CGFloat gradientColors[8] = {1.0f, 1.0f, 1.0f, 0.25f, 0.0f, 1.0f, 0.0f, 0.25f};
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, gradientColors, gradientLocations, 2);
CGColorSpaceRelease(colorSpace);

CGPoint gradientCenter = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect));
CGFloat gradientRadius = MIN(rect.size.width, rect.size.height) / 2;

CGContextDrawRadialGradient(context, gradient, gradientCenter, 0, gradientCenter, gradientRadius, kCGGradientDrawsAfterEndLocation);

CGGradientRelease(gradient);


}

然后在您的 MKMapView 委托(delegate)中,实现以下方法...

-(MKOverlayRenderer *)mapView:(MKMapView*)mapView rendererForOverlay:(id<MKOverlay>)overlay {

MKCircle * circle = (MKCircle *)overlay;

MKGradientCircleRenderer * renderer = [[MKGradientCircleRenderer alloc] initWithCircle:circle];

return renderer;

}

这将允许您实现相同的效果,但使用的是 iOS 7 中可用的新方法。

关于iphone - 如何绘制填充颜色不是纯色而是图像的 MKCircle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14566614/

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