Всплывающее окно для карты

Описание: всплывающее окно для карты, созданное пользователем.

Файл «CustomMapBubblePopoverView.h»

#import <MapCharting/MapCharting.h>
@interface CustomMapBubblePopoverView : MapBubblePopoverView
@end

Файл «CustomMapBubblePopoverView.m»

#import "CustomMapBubblePopoverView.h"
@implementation CustomMapBubblePopoverView
// Инициализирует всплывающее окно
- (id)init
{
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        self.contentMode = UIViewContentModeRedraw;
    }
    return self;
}
- (void)drawRect:(CGRect)rect
{
    // Получаем текущий графический контекст
    CGContextRef context = UIGraphicsGetCurrentContext();
    // Отрисовываем всплывающее окно
    [self drawInContext:context boundsRect:[self bounds]];
}
// Отрисовывает всплывающее окно
- (void) drawInContext: (CGContextRef) context boundsRect: (CGRect) boundsRect
{
    MapPlaced *placed = [self placed];
    // Создаём всплывающее окно
    CGPathRef path = createBubble(
    CGRectMake(0.5,0.5, boundsRect.size.width-1,
    boundsRect.size.height-1),
    [placed borderRadius],
    0.5,
    14, 11,
    [self arrowOrientation]);
    CGContextSetAlpha(context, 1.0);
    // Устанавливаем заливку
    [[placed background] applyToContext:context path:path rect:boundsRect];
    CGContextSetAlpha(context, 1.0);
    CGContextSetStrokeColorWithColor(context, [[self borderColor] CGColor]);
    CGContextAddPath(context, path);
    // Устанавливает толщину границы всплывающего окна
    CGContextSetLineWidth(context, [placed borderThickness]);
    CGContextStrokePath(context);
    // Определяем расположение подписи в данном окне
    CGPoint centerPoint = boundsRect.origin;
    centerPoint.x += boundsRect.size.width / 2 - 10;
    centerPoint.y += boundsRect.size.height / 4;
    // Задаём цвет подписи
    [[self tintColor] set];
    // Отрисовываем подпись
    [[placed ID] drawAtPoint:centerPoint withFont:[UIFont fontWithName:@"Arial" size:14]];
    CGPathRelease(path);
}
@end

См. также:

Создание всплывающего окна для карты