Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9074629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:40:56+00:00 2026-06-16T18:40:56+00:00

I have a UISegmentedControl on my view using storyboard and the text is currently

  • 0

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..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T18:40:57+00:00Added an answer on June 16, 2026 at 6:40 pm

    I have seen your code, that contains a very hard way to get a month from NSDate I 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 from NSDate.

    NSDate *today = [NSDate date];
    NSCalendar *gregorian = [[NSCalendar alloc]
                             initWithCalendarIdentifier:NSGregorianCalendar];
    NSDateComponents *components = [gregorian components:NSMonthCalendarUnit fromDate:today];
    NSInteger currentMonth = [components month]; // this will give you the integer for the month number
    
    [components setMonth:1];
    NSDate *newDate = [gregorian dateByAddingComponents:components toDate:today options:0];
    NSDateComponents *nextComponents = [gregorian components:NSMonthCalendarUnit fromDate:newDate];
    

    UPDATED:

    NSInteger nextMonth = [nextComponents month]; // this will give you the integer for the month number
    

    and as @Prince said you can get the name of the month from NSDateFormatter. Anyway I repeat to make you understand.

    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    NSString *currentMonthName = [[df monthSymbols] objectAtIndex:(currentMonth-1)];
    NSString *nextMonthName = [[df monthSymbols] objectAtIndex:(nextMonth-1)];
    
    [segMonth setTitle:currentMonthName forSegmentAtIndex:0];
    [segMonth setTitle:nextMonthName forSegmentAtIndex:1];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a UISegmentedControl set to add/remove table view cells when its value
I have created a UISegmentedControl with two segments using the interface builder (from storyboard),
In my loadView methoad of my view controller I have the following code: //
I have a UISegmentedControl on a black UIToolbar. I have set the style to
I have implemented UISegmentedControl with Direction theme using BASequenceControl from cocoacontrols.com . I have
Xcode, Obj-c, iOS 5.2 iOS 6.0 I have a UISegmentedControl which is being inserted
I have a view that has a UISegmentedControl in its bottom UIToolBar with 2
I'm making an app and i have a view controller with a UISegmentedControl, and
I have some details stored inside an NSDictionary. I'm using a Master-Detail view on
I'm using a UISegmentedControl in a view to select a specific client. This is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.