【问题标题】:iOS MKAnnotation subtitle with NSMutableAttributedString possible可能带有 NSMutableAttributedString 的 iOS MKAnnotation 字幕
【发布时间】:2014-05-20 16:10:49
【问题描述】:

我正在尝试让 MKAnnotation 字幕具有彩色文本,但我无法使用 NSMutableAttributedString 实现。

有人知道如何实现吗?

我当前的代码:

customAnn.h

interface MapAnnotation : NSObject <MKAnnotation>

@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
@end

customAnn.m

@implementation MapAnnotation

- (NSString *)title
{
    return @"Some Title";
}

- (NSString *)subtitle
{
    NSMutableAttributedString *subPart = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@ ", [[[data valueForKey:@"16"] sortedArrayUsingSelector: @selector(localizedStandardCompare:)] componentsJoinedByString:@" "]]];
    [subPart addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:20/225.0 green:30/255.0 blue:15/255.0 alpha:1] range:NSMakeRange(0, subPart.length)];
    return subPart;
}
@end

目前代码不工作,因为 - (NSString *)subtitle 想要 NSString 但得到 NSMutableAttributedString - 它崩溃,但如果更改为 - (NSMutableAttributedString *)subtitle 我什至无法编译。

我不知道如何实现这一点。

谢谢。

【问题讨论】:

  • 给我们一些代码示例,以便我们为您提供帮助。

标签: ios mkannotation nsattributedstring subtitle callout


【解决方案1】:

我认为您无法使用股票 MKAnnotation 来做到这一点。我会创建自己的自定义注释视图,这样您就可以根据需要自定义视图。

这是一个很好的教程:

http://blog.asynchrony.com/2010/09/building-custom-map-annotation-callouts-part-1/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 2015-11-13
    相关资源
    最近更新 更多