我有我的觀點一個UISegmentedControl
用故事板和文本目前正在設定編程方式使用下面的代碼行:使用此代碼設置UISegmentedControl文本編程方式從變量
[segMonth setTitle:@"Month 1" forSegmentAtIndex:0];
[segMonth setTitle:@"Month 2" forSegmentAtIndex:1];
我也有一個日期函數獲取當前月份的數字(1-12):
// Date
NSDate *now = [NSDate date];
NSString *strDate = [[NSString alloc] initWithFormat:@"%@",now];
NSArray *arr = [strDate componentsSeparatedByString:@" "];
NSString *str;
str = [arr objectAtIndex:0];
NSArray *arr_my = [str componentsSeparatedByString:@"-"];
NSInteger month = [[arr_my objectAtIndex:1] intValue];
//End Date
我想名字的第一個段當月「月」和第二段下個月「一月」。
我曾嘗試使用下面的代碼嘗試,但它似乎沒有工作:
[segMonth setTitle:@"%d" forSegmentAtIndex:0];
[segMonth setTitle:@"%d" forSegmentAtIndex:1];
顯然,這也將只給了一個月,不是名稱的數量..
http://stackoverflow.com/questions/4488373/ios-how-to-get-a-proper-month-name-from-a-number –