
- (MKAnnotationVIEw *)mapVIEw:(MKMapVIEw *)mapVIEw vIEwForAnnotation:(ID <MKAnnotation>)annotation { MKAnnotationVIEw *annotationVIEw = [mapVIEw dequeueReusableAnnotationVIEwWithIDentifIEr:@"String"]; if(!annotationVIEw) { annotationVIEw = [[MKAnnotationVIEw alloc] initWithAnnotation:annotation reuseIDentifIEr:@"String"]; UIbutton *directionbutton = [UIbutton buttonWithType:UIbuttonTypeCustom]; UIImage *directionIcon = [UIImage imagenamed:@"IconDirections"]; [directionbutton setimage:directionIcon forState:UIControlStatenormal]; annotationVIEw.rightCalloutAccessoryVIEw = directionbutton; } annotationVIEw.enabled = YES; annotationVIEw.canShowCallout = YES; return annotationVIEw;}@H_301_12@解决方法 有两个主要问题: >未设置自定义标注按钮的框架,使其基本上不可见.
>正在创建MKAnnotationVIEw,但未设置其图像属性(注释本身的图像 – 而不是标注按钮).这使得整个注释不可见.
对于问题1,将按钮的框架设置为适当的值.例如:
UIImage *directionIcon = [UIImage imagenamed:@"IconDirections"];directionbutton.frame = CGRectMake(0,directionIcon.size.wIDth,directionIcon.size.height);@H_301_12@ 对于问题2,设置注释视图的图像(或创建MKPinAnnotationVIEw):
annotationVIEw.image = [UIImage imagenamed:@"SomeIcon"];@H_301_12@ 此外,您应该通过更新注释属性来正确处理视图重用.
完整的例子:
- (MKAnnotationVIEw *)mapVIEw:(MKMapVIEw *)mapVIEw vIEwForAnnotation:(ID <MKAnnotation>)annotation { MKAnnotationVIEw *annotationVIEw = [mapVIEw dequeueReusableAnnotationVIEwWithIDentifIEr:@"String"]; if(!annotationVIEw) { annotationVIEw = [[MKAnnotationVIEw alloc] initWithAnnotation:annotation reuseIDentifIEr:@"String"]; annotationVIEw.image = [UIImage imagenamed:@"SomeIcon"]; UIbutton *directionbutton = [UIbutton buttonWithType:UIbuttonTypeCustom]; UIImage *directionIcon = [UIImage imagenamed:@"IconDirections"]; directionbutton.frame = CGRectMake(0,directionIcon.size.height); [directionbutton setimage:directionIcon forState:UIControlStatenormal]; annotationVIEw.rightCalloutAccessoryVIEw = directionbutton; annotationVIEw.enabled = YES; annotationVIEw.canShowCallout = YES; } else { //update annotation to current if re-using a vIEw annotationVIEw.annotation = annotation; } return annotationVIEw;}@H_301_12@ 总结 以上是内存溢出为你收集整理的ios – MKAnnotationView自定义按钮图像全部内容,希望文章能够帮你解决ios – MKAnnotationView自定义按钮图像所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)