ios - 在自定义注释之上显示用户个人资料图像

标签 ios ios7 mapkit mkannotationview

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

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

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

enter image description here

最佳答案

想通了:

添加了一个 UIImageView 作为 MKAnnotationView 的 subview :

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 类别。

关于ios - 在自定义注释之上显示用户个人资料图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25014576/

相关文章:

iphone - MKMapView 不调用委托(delegate)方法

ios - 当更改数据源中的子对象时,UITableView reloadData 不起作用。

ios - 如何处理 UIViewController 中的键盘快捷键

c# - 如何删除 UIButton 设置的默认约束?

ios - SLComposeViewController 深色键盘外观

objective-c - MKMapView 平移导致父 UIScrollView 滚动

ios - AF网络 : Handling of asynchronous get request with AFJSONRequestOperation

jquery 窗口高度 iOS 7

ios - 在启动画面中使用 AdMob

iphone - 清除 MKMapView 的图 block 缓存吗?