I have a UISegmentedControl on my view using storyboard and the text is currently being set programatically using the following lines of code:
[segMonth setTitle:@"Month 1" forSegmentAtIndex:0];
[segMonth setTitle:@"Month 2" forSegmentAtIndex:1];
I also have a date function using this code which gets the number (1-12) of the current month:
// 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
I’m trying to name the first segment the current month ‘December’ and the second segment the next month ‘January’.
I have tried using the following code but it doesn’t seem to work:
[segMonth setTitle:@"%d" forSegmentAtIndex:0];
[segMonth setTitle:@"%d" forSegmentAtIndex:1];
Obviously that would also only give the number of the month, not the name..
I have seen your code, that contains a very hard way to get a month from
NSDateI know, this may not be the answer. But I am just asking you to check this code to know the correct way to get the month or day or time or anything separated fromNSDate.UPDATED:
and as @Prince said you can get the name of the month from
NSDateFormatter. Anyway I repeat to make you understand.