嗨,我试图设置一个背景图像在我的详细披露UIButton附加到我的MapView MKAnnotation标注视图。检查堆栈溢出--有一致的例子说明如何设置它,但是它似乎不适用于我的标注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‘
谢谢你在这方面的帮助
发布于 2015-10-26 06:06:05
您的问题是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-26 06:01:49
如果键入按钮DetailDisclosure,则不能设置背景图像。您可以在rightCalloutAccessoryView中添加子视图图像,但不需要按钮。
因此,如果仍然使用类型按钮DetailDisclosure,则不能设置背景
https://stackoverflow.com/questions/33339232
复制相似问题