ios 在地图上画一个带箭头半透明的气泡框

先上一个效果图

ios 在地图上画一个带箭头半透明的气泡框_第1张图片
2986906-5ba5a85f708afb54.png
- (instancetype)initWithFrame:(CGRect)frame{

if (self = [super initWithFrame:frame]) {

self.backgroundColor = [UIColor clearColor];

//这里可以设置你要在气泡view上显示的内容

}

return self;

}

//通过drawRect 画一个 带箭头的气泡框

- (void)drawRect:(CGRect)rect {

[self drawInContext:UIGraphicsGetCurrentContext()];

self.layer.shadowColor = [[UIColor clearColor] CGColor];

self.layer.shadowOpacity = 1.0;

self.layer.shadowOffset = CGSizeMake(0.0f, 0.0f);

}

-(void)drawInContext:(CGContextRef)context{

CGContextSetLineWidth(context, 2.0);

CGContextSetFillColorWithColor(context, [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5].CGColor);

[self getDrawPath:context];

CGContextFillPath(context);

}

-(void)getDrawPath:(CGContextRef)context{

CGRect rrect = self.bounds;

CGFloat radius = 20.0;

CGFloat minx = CGRectGetMinX(rrect),

midx = CGRectGetMidX(rrect),

maxx = CGRectGetMaxX(rrect);

CGFloat miny = CGRectGetMinY(rrect),

maxy = CGRectGetMaxY(rrect)-10;

CGContextMoveToPoint(context, midx+10, maxy);

CGContextAddLineToPoint(context, midx, maxy+10);

CGContextAddLineToPoint(context, midx-10, maxy);

CGContextAddArcToPoint(context, minx, maxy, minx, miny, radius);

CGContextAddArcToPoint(context, minx, miny, maxx, miny, radius);

CGContextAddArcToPoint(context, maxx, miny, maxx, maxy, radius);

CGContextAddArcToPoint(context, maxx, maxy, midx, maxy, radius);

CGContextClosePath(context);

}

你可能感兴趣的:(ios 在地图上画一个带箭头半透明的气泡框)