开发者

iOS Mapkit Custom image appears 2X larger

开发者 https://www.devze.com 2023-03-23 21:40 出处:网络
am using the following image [using Annotations, MapkitView etc], to mark some locations. But, when the images are displayed, they appe开发者_C百科ar 2X bigger.

am using the following image [using Annotations, MapkitView etc], to mark some locations. But, when the images are displayed, they appe开发者_C百科ar 2X bigger. Is this normal?

Here is an inherited class, that I use

@interface ImageAnnotationView : MKAnnotationView {
        UIImageView *_imageView;
        id m_parent;
        BusinessMapAnnotation *m_annotation;

        NSString *stitle;
    }


    - (id)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier
    {
        self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
        self.backgroundColor = [UIColor clearColor];

        self.m_annotation = (BusinessMapAnnotation*)annotation;

        self.stitle = m_annotation.sTitle;
        _imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:([stitle isEqualToString:@"You are here"]) ? @"Pushpin_large.png":@"NearPin.png"]];
        _imageView.contentMode = UIViewContentModeCenter;

        [self addSubview:_imageView];
        _imageView.center = ([stitle isEqualToString:@"You are here"]) ? CGPointMake(15.0, -10.0):CGPointMake(kWidth/2, 0.0);

        return self;
    }


If your images are made for retina-display quality resolution but do not have @2x appended to the end of the filename (i.e. 'Pushpin_large@2x.png' as the file name in your project folder) then they will appear two times larger when drawn. If this is the case, don't change your code, just append @2x to the filename.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号