0

我尝试这样,但它不起作用。我怎样才能做到这一点 ?

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];
4

1 回答 1

1

首先,您为pointText UITextField设置了错误的框架,纬度和经度不是屏幕坐标,应该这样实现:

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

您可能需要设置canShowCallout为 YES:

pointTest.canShowCallout = YES;

然后,您将 设置rightCalloutAccessoryViewUITextField,这不是最好的选择。为此属性指定的常见视图是UIButton类型设置为 的对象UIButtonTypeDetailDisclosure。对于标题和副标题,我更喜欢使用annotation属性:

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

您应该查看苹果文档

于 2013-11-05T23:11:05.443 回答