如何在MKAnnotationView标题中添加UITextField

编程入门 行业动态 更新时间:2024-10-28 17:23:30
本文介绍了如何在MKAnnotationView标题中添加UITextField的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我尝试这样,但这是行不通的.我该怎么办?

I try like this, but it isn't work. How can i do this ?

MKAnnotationView *pointTest = [[MKAnnotationView alloc] init]; pointTest.annotation = point; pointTest.draggable= YES; UITextField *pointText = [[UITextField alloc] initWithFrame:CGRectMake(location.latitude, location.longitude, 100, 20)]; pointText.backgroundColor = [UIColor blackColor]; pointTest.rightCalloutAccessoryView = pointText; pointTest.canShowCallout = YES; [self.userMap addAnnotation:pointTest];

推荐答案

首先,您为 pointText UITextField,纬度和经度不是屏幕坐标,应按以下方式实现:

First of all, you are setting a wrong frame for the pointText UITextField, latitude and longitude are not screen coordinates, it should be implemented like this:

CGFloat originX = 0; //Or other value CGFLoat originY = 0; //Or other value UITextField *pointText = [[UITextField alloc] initWithFrame:CGRectMake(originX, originY, 100, 20)];

您可能也需要将canShowCallout设置为是":

You may also need to set canShowCallout to YES:

pointTest.canShowCallout = YES;

然后,您正在将rightCalloutAccessoryView设置为UITextField,这不是最好的选择.为此属性指定的常见视图是UIButton对象,其类型设置为UIButtonTypeDetailDisclosure.对于标题和字幕,我更喜欢使用 annotation 属性:

Then, you are setting the rightCalloutAccessoryView as an UITextField, which is not the best thing to do. A common view to specify for this property is UIButton object whose type is set to UIButtonTypeDetailDisclosure. For titles and subtitles, I prefer using the annotation attribute:

point.title = "Your title"; pointTest.annotation = point;

您应检查苹果文档.

You should check the apple documentation.

更多推荐

如何在MKAnnotationView标题中添加UITextField

本文发布于:2023-10-07 22:23:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1470684.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标题   如何在   MKAnnotationView   UITextField

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!