我正在尝试让 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
我什至无法编译。
我没有其他想法如何实现这一点。
谢谢。