I'm trying to have MKAnnotation subtitle to have colored text, but I can't achieve that with NSMutableAttributedString.
Does anyone have a idea how to achieve that?
My current code:
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
Currently the code is NOT working because - (NSString *)subtitle
wants NSString
but gets NSMutableAttributedString
- it crashes, but if change to - (NSMutableAttributedString *)subtitle
I can't even get it to compile.
I have no other ideas how to realize this.
Thanks.