0

嗨,我正在尝试在附加到 MapView MKAnnotation 标注视图的详细信息披露 UIButton 上设置背景图像。检查stackoverflow有如何设置它的一致示例,但是它似乎不适用于我的标注UIButton。我的问题是,这不起作用,仅仅是因为地图视图还是我错过了其他东西?这是我的代码:

// If an existing pin view was not available, create one.
            pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"CustomPinAnnotationView"];
            pinView.canShowCallout = YES;
            pinView.image = [UIImage imageNamed:@"Tch4"];
            //pinView.calloutOffset = CGPointMake(0, 32);
            pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
            UIImage *btnImage = [UIImage imageNamed:@"4stars"];
            [pinView.rightCalloutAccessoryView setBackgroundImage:btnImage forState:UIControlStateNormal];

我在最后一行收到错误。错误是:UIView 没有可见接口声明选择器“setbackgroundimage:forstate”

感谢您对此的帮助

4

2 回答 2

1

您的问题是rightCalloutAccessoryView返回一个UIView实例。并且UIView不响应setBackgroundImage:forState:方法。

您正在寻找的是添加一个UIButton类似这样的东西:

UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeCustom];
infoButton.frame = CGRectMake(0, 0, 32, 32); // Set your own frame 
[infoButton setBackgroundImage:btnImage forState:UIControlStateNormal];
[infoButton setBackgroundImage:btnImage forState:UIControlStateSelected];
pinView.rightCalloutAccessoryView = infoButton;
于 2015-10-26T06:06:05.440 回答
0

如果您的 typebutton DetailDisclosure,则无法设置背景图像。您可以将子视图图像添加到 rightCalloutAccessoryView 但没有按钮..

所以如果你仍然使用 typebutton DetailDisclosure 你不能设置背景

于 2015-10-26T06:01:49.900 回答