相关疑难解决方法(0)

如何为MKAnnotation的字幕显示2行文本并更改右侧按钮的图像?

我正在查看Apple的MapCallouts示例,用于地图注释和标注(==当您点击图钉时出现的气泡).每个注释都有坐标,标题和副标题.我想在2行显示字幕,我试过:

- (NSString *)subtitle
{
return @"Founded: June 29, 1776\nSecond line text";
}
Run Code Online (Sandbox Code Playgroud)

但文本"第二行文字"保持在一行,使泡沫更宽.我明白了:

在此输入图像描述

我还想将按钮的图像更改为我自己的图像,设置按钮的代码当前是这样的:

UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

编辑:我尝试了7KV7的建议.按钮更改成功,但我仍然无法获得2行字幕.我的代码:

MKPinAnnotationView* customPinView = [[[MKPinAnnotationView alloc]
                                        initWithAnnotation:annotation reuseIdentifier:BridgeAnnotationIdentifier] autorelease];
        customPinView.pinColor = MKPinAnnotationColorPurple;
        customPinView.animatesDrop = YES;


        // Button
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(0, 0, 23, 23);
        button.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;

        //UIEdgeInsets titleInsets = UIEdgeInsetsMake(7.0, -20.0, 7.0, 7.0);
        //button.titleEdgeInsets = titleInsets;

        [button setImage:[UIImage imageNamed:@"ic_phone_default.png"] forState:UIControlStateNormal];
        //[button setImage:[UIImage imageNamed:@"ic_phone_selected.png"] forState:UIControlStateSelected];
        [button setImage:[UIImage imageNamed:@"ic_phone_selected.png"] forState:UIControlStateHighlighted];
        [button addTarget:self action:@selector(showDetails:) …
Run Code Online (Sandbox Code Playgroud)

iphone mkmapview mkannotation

14
推荐指数
2
解决办法
3万
查看次数

标签 统计

iphone ×1

mkannotation ×1

mkmapview ×1