【问题标题】:How to change annotation callout button color in iphone?如何更改 iphone 中的注释标注按钮颜色?
【发布时间】:2011-12-19 14:19:01
【问题描述】:

我想将上面的蓝色标注按钮更改为灰色。这个怎么做?? 这也可以使整个注释气泡可点击???谁能建议我 方法。

【问题讨论】:

    标签: iphone mapkit mkannotation


    【解决方案1】:

    您可能正在添加类似这样的蓝色按钮

    - (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{
    MKPinAnnotationView *annView=(MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"annViewIdentifier"];
    
        if (annView == nil) {
            annView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"annViewIdentifier"] autorelease];
        }
    UIButton *infoDefaultButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    
            [infoDefaultButton addTarget:self
                           action:@selector(showDetails:)
                 forControlEvents:UIControlEventTouchUpInside];
            annView.rightCalloutAccessoryView = infoDefaultButton;
    
    }
    

    如果您想要任何自定义按钮,则可以添加 UIButtonTypeCustom 而不是 UIButtonTypeDetailDisclosure 并设置其框架。

    【讨论】:

    • annView.image = [UIImage imageNamed:@"flag.png"]; annView.annotation = 注释; UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeCustom]; NSInteger annotationValue = [self.annobjs indexOfObject:annotation]; rightButton.frame = CGRectMake(5, 100, 10, 10); rightButton.tag = annotationValue; UIImage *grayImage = [UIImage imageNamed:@"arrow.png"]; [rightButton setBackgroundImage:grayImage forState:UIControlStateHighlighted];[rightButton addTarget:self action:@selector(showDetails:)forControlEvents:UIControlEventTouchUpInside];annView.rightCalloutAccessoryView = rightButton;
    • 好的...CGRectMake(0, 0, 23, 23);这是有效的,但首先没有显示图像。还剩什么???
    • 我刚刚按照你说的做了,但是我的按钮图像没有显示。它仅在单击该按钮位置后显示。在弹出的标题和子标题上只可见......有什么可以解决的吗??
    • 我认为它应该这样工作。我还没有测试过代码.. 抱歉,如果它不起作用。您可以尝试按照教程获取自定义注释标注(标注气泡和附件视图的自定义大小)“dev.tuyennguyen.ca/?p=301”。我会自己尝试这个东西,如果找到任何解决方案,我会告诉你。
    • 嘿,您的解决方案正在运行,现在可以看到右侧标注按钮,并将 UIControlStateHighlighted 更改为 UIControlStateNormal。感谢安娜卡列尼娜和你
    猜你喜欢
    • 1970-01-01
    • 2021-12-27
    • 2011-10-22
    • 2023-03-21
    • 2016-09-18
    • 2012-08-25
    • 2023-02-07
    • 1970-01-01
    • 2015-12-16
    相关资源
    最近更新 更多