【问题标题】:Show user profile images on top of the custom annotation在自定义注释顶部显示用户个人资料图像
【发布时间】:2014-07-29 11:48:15
【问题描述】:

我能够添加自定义注释图像来替换默认标记,但我不知道如何在其上添加用户图像。我需要从 URL 加载用户图像。

附言我需要一个 iOS 7 解决方案。

这基本上是我想要实现的(取自另一个应用程序):

【问题讨论】:

    标签: ios ios7 mapkit mkannotationview


    【解决方案1】:

    想通了:

    将 UIImageView 作为子视图添加到 MKAnnotationView:

    MKAnnotationView *pinView = (MKAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:@"CustomPinAnnotationView"];
    pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"CustomPinAnnotationView"];
    pinView.canShowCallout = YES;
    pinView.image = [UIImage imageNamed:@"icon-map-placemark-68x80"];
    pinView.calloutOffset = CGPointMake(0, -5);
    
    UIImageView *profileImageView = [[UIImageView alloc]init];
    profileImageView.frame = CGRectMake(6, 7, 55, 55);
    profileImageView.layer.masksToBounds = YES;
    profileImageView.layer.cornerRadius = 27;          
    [profileImageView setImageWithURL:[NSURL URLWithString:@"http://domain.com/avatar.jpg"]];
    
    [pinView addSubview:profileImageView];
    

    附言要显示来自 URL 的图像,我使用的是 SDWebImage/UIImageView+WebCache.h 类别。

    【讨论】:

      猜你喜欢
      • 2021-08-14
      • 1970-01-01
      • 1970-01-01
      • 2014-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多