objective-c – iOS中的自定义注释图像
发布时间:2020-12-16 03:46:56 所属栏目:百科 来源:网络整理
导读:我试图用特定的图像替换典型的iOS mapkit“pin”.我是编码的新手,所以我不确定为什么这不起作用,但这是我尝试过的: 对于该方法 - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id MKAnnotation)annotation{ 除此之外,我还有: pin
我试图用特定的图像替换典型的iOS mapkit“pin”.我是编码的新手,所以我不确定为什么这不起作用,但这是我尝试过的:
对于该方法 - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation { 除此之外,我还有: pinView.animatesDrop=YES; pinView.canShowCallout=YES; //pinView.pinColor=MKPinAnnotationColorPurple; UIImage *pinImage = [UIImage imageNamed:@"Jeff.png"]; [pinView setImage:pinImage]; 但是,即使代码编译得很好,pinView也没有设置pinImage.任何想法为什么不呢? 解决方法
您所要做的就是将最后一行更改为:
[pinView addSubview:pinImage]; 完整的例子: - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation { MKPinAnnotationView *annView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"ParkingPin"]; UIImageView *imageView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pin_parking.png"]] autorelease]; annView.animatesDrop = TRUE; annView.canShowCallout = YES; annView.calloutOffset = CGPointMake(-5,5); [annView addSubview:imageView]; return annView; } 希望这可以帮助! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |