Skip to content

Instantly share code, notes, and snippets.

View futuretap's full-sized avatar

Ortwin Gentz, FutureTap futuretap

View GitHub Profile
@futuretap
futuretap / NSDate+Additions.m
Created March 22, 2018 10:22
relative time formatter
- (NSString*)localizedRelativeTime {
NSDateComponentsFormatter *formatter = [[NSDateComponentsFormatter alloc] init];
formatter.allowedUnits = NSCalendarUnitHour | NSCalendarUnitMinute;
formatter.unitsStyle = NSDateComponentsFormatterUnitsStyleShort;
if (self.timeIntervalSinceNow < 60 && self.timeIntervalSinceNow > -60) {
return NSLocalizedString(@"right now", @"from MapKit/Maps");
} else if (self.timeIntervalSinceNow > 0) {
NSString *start = [formatter stringFromDate:NSDate.date toDate:self];
return [NSString stringWithFormat:NSLocalizedString(@"in %@", @"placeholder: minutes/hours"), start];
} else {
/*
Maps.app uses its own custom marker annotations. Their icon is smaller (FB10143146), the title can be colored (FB9739380)
which is all pretty nice. Unfortunately, they’re not exposed as API. (Hence the feedbacks to expose them.)
Out of curiosity, I tried to hack around with MapKit to display them. Unfortunately, I didn’t succeed. Here’s what I tried:
I discovered _MKBalloonLabelMarkerView and its superclass _MKLabelMarkerView which might be the ones I’m looking for
(I might be wrong).
We can instantiate them using: