[英]how to add UITextField in MKAnnotationView Title
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];
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: 首先 ,您为pointText
UITextField
设置了错误的框架,纬度和经度不是屏幕坐标,应该这样实现:
CGFloat originX = 0; //Or other value
CGFLoat originY = 0; //Or other value
UITextField *pointText = [[UITextField alloc] initWithFrame:CGRectMake(originX, originY, 100, 20)];
You may also need to set canShowCallout
to YES: 您可能还需要将
canShowCallout
设置为YES:
pointTest.canShowCallout = YES;
Then , you are setting the rightCalloutAccessoryView
as an UITextField
, which is not the best thing to do. 然后 ,您将
rightCalloutAccessoryView
设置为UITextField
,这不是最好的选择。 A common view to specify for this property is UIButton
object whose type is set to UIButtonTypeDetailDisclosure
. 为此属性指定的常见视图是
UIButton
对象,其类型设置为UIButtonTypeDetailDisclosure
。 For titles and subtitles, I prefer using the annotation attribute: 对于标题和字幕,我更喜欢使用注释属性:
point.title = "Your title";
pointTest.annotation = point;
You should check the apple documentation . 您应该检查Apple文档 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.