2012-03-24 59 views
0

我有一個包裹UIDatePicker的邊框,用自定義視圖隱藏周圍的藍色。我知道在時間模式下,它不是可以將其設置爲特定的AM/PM日期選擇器,或24小時日期選擇器。不過,我想知道如何找出它目前的設置,因此我可以調整我的邊框,因爲它們都是不同的大小。檢查24小時模式或上午/下午模式,與UIDatePicker一起使用

回答

4

這是很容易,你應該檢查一下AMSymbol和PMSymbol是 「NSNotFound」 在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); 
} 
相關問題