【发布时间】: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