How to Align Text in MKAnnotation subtitle


I’ve finished the challenges on p.120 and was annoyed by the subtitle text (date), being left justified. I searched the documentation thinking ‘it shouldn’t be too hard to center this text’. Several hours later, here I am! I think (hope) I’m close, just missing something small… Help!


#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
#import <UIKit/UIKit.h>

@interface BNRMapPoint : NSObject <MKAnnotation>
// A new designated initializer for instances of BNRMappoint
- (id)initWithCoordinate:(CLLocationCoordinate2D)c title:(NSString *)t;

// This is a required property from MKAnnotation
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;

// This is an optional property from MKAnnotation
@property (nonatomic, copy) NSString *title;

// ***Gold Challenge (p.120)
@property (nonatomic, copy) NSString *subtitle;

// Extra credit (centering the text on subtitle)
@property (nonatomic) UITextAlignment textAlignment;


#import "BNRMapPoint.h"

@implementation BNRMapPoint

@synthesize coordinate, title, subtitle;

- (id)initWithCoordinate:(CLLocationCoordinate2D)c title:(NSString *)t
    self = [super init];
    if (self) {
        coordinate = c;
        [self setTitle:t];
        // ***Gold Challenge (p.120)***
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateStyle:NSDateFormatterShortStyle];
        NSDate *date = [NSDate date];
        [self setSubtitle:[NSString stringWithFormat:@"%@", [dateFormatter stringFromDate:date]]];
        // Want to figure out how to center the date subtitle. This is not working!
        [self setTextAlignment:UITextAlignmentCenter];
    return self;
// Tried to override the 'setter' to set default from align'left' to 'center'. This is not working!
- (void)setTextAlignment:(UITextAlignment)textAlignment
    textAlignment = UITextAlignmentCenter;
- (id)init
    return [self initWithCoordinate:CLLocationCoordinate2DMake(43.07, -89.32)