0

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.

user2570174
  • 601
  • 1
  • 6
  • 9

1 Answers1

0

I don't think you'll be able to do that with a stock MKAnnotation. I would create my own custom annotation view, that way you can customize the view however you want.

Here's a good tutorial:

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

Mike
  • 9,765
  • 5
  • 34
  • 59