Reputation: 16051
I have a border which wraps around UIDatePicker, to hide the blue surrounding it with a custom view.. I'm aware that in time mode, it's not possible to set it as specifically an AM/PM datepicker, or as a 24 hour datepicker. I'm wondering how I would go about finding out what it's currently set at, though, so I can adjust my border around that, as they're both different sizes.
Upvotes: 0
Views: 720
Reputation: 1561
It's pretty easy, you should check if AMSymbol and PMSymbol is "NSNotFound" in myDateString:
+(BOOL) is24h {
NSDateFormatter *myFormatter = [[NSDateFormatter alloc] init];
[myFormatter setLocale:[NSLocale currentLocale]];
[myFormatter setDateStyle:NSDateFormatterNoStyle];
[myFormatter setTimeStyle:NSDateFormatterShortStyle];
NSString *myDateString = [myFormatter stringFromDate:[NSDate date]];
NSRange myAmRange = [myDateString rangeOfString:[myFormatter AMSymbol]];
NSRange myPmRange = [myDateString rangeOfString:[myFormatter PMSymbol]];
return (myAmRange.location == NSNotFound && myPmRange.location == NSNotFound);
}
Upvotes: 4