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

  • Home
  • SEARCH
  • 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 6054975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:12:46+00:00 2026-05-23T08:12:46+00:00

i am trying to implement an arabic datepicker. after a small research (and found

  • 0

i am trying to implement an arabic datepicker. after a small research (and found nothing) i found this as the only solution: (am i right?)

create a custom UIPickerView with 3 components for the days, months, and years.

the real problem is that i want to set a maximum date, for example [NSDate date].

do i have to code it all, or there is a simpler way of doing it… anything will help.

Thank you.

  • 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-05-23T08:12:47+00:00Added an answer on May 23, 2026 at 8:12 am

    Since the approach madhu proposed was not general, i finally made my own Arabic date picker.

    These are the .h and the .m files that may help someone someday… an instance of these files is added as a subview to another view containing various other cell types.

    the code is very messy, and may contain super ugly and deep leeks, but it works (for now).

    dateCell.h:

    #import <UIKit/UIKit.h>
    
    
    @interface dateCell : UIViewController<UIActionSheetDelegate,UIPickerViewDelegate,UIPickerViewDataSource> {
    
        IBOutlet UILabel *l;
        IBOutlet UITextField *t;
        IBOutlet UIButton *b;
    
        UIPickerView *picker;
        UIActionSheet *actionSheet;
    
        NSDictionary *numbers;
        NSDictionary *months;
        int year;
        int month;
        int day;
    
        //properties
        NSString *str;
        NSString *name;
        NSString *limit;
        BOOL save;
    
    }
    
    @property (nonatomic, retain) IBOutlet UILabel *l;
    @property (nonatomic, retain) IBOutlet UITextField *t;
    @property (nonatomic, retain) IBOutlet UIButton *b;
    
    @property (nonatomic, retain) NSString *str;
    @property (nonatomic, retain) NSString *name;
    @property (nonatomic, retain) NSString *limit;
    @property (nonatomic) BOOL save;
    @property (nonatomic, retain) UIView* target;
    @property (nonatomic, retain) NSDictionary *numbers;
    @property (nonatomic, retain) NSDictionary *months;
    @property (nonatomic, retain) UIPickerView *picker;
    @property (nonatomic, retain) UIActionSheet *actionSheet;
    
    -(IBAction) bPressed;
    -(void) setTarget:(UIView *)tar;
    -(void)showPicker;
    -(int)getYear;
    -(NSString*)translateYear:(int)iYear;
    -(int) getDay;
    -(int) getMonth;
    -(int)getNumberOfDaysinYear:(int)y andMonth:(int)m;
    - (void)changeDateInLabel:(id)sender;
    
    @end
    

    dateCell.m:

    #import "dateCell.h"
    
    
    @implementation dateCell
    @synthesize l,t,b;
    @synthesize name, limit, save,str,target,numbers,months,picker,actionSheet;
    
    - (void)viewDidLoad {
        [super viewDidLoad];
    }
    
    -(void)loadView{
        [super loadView];
        l.text=str;
    
    
        NSArray *aDays=[[[NSArray alloc] initWithObjects:@"١",@"٢",@"٣",@"٤",@"٥",@"٦",@"٧",@"٨",@"٩",@"٠",nil] autorelease];
        NSArray *eDays=[[[NSArray alloc] initWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"0",nil] autorelease];
        numbers=[[NSDictionary alloc] initWithObjects:aDays forKeys:eDays];
    
        NSArray *aMonths=[[[NSArray alloc] initWithObjects:@"يناير",@"فبراير",@"مارس",@"أبريل",@"مايو",@"يونيو",@"يولي",@"أغسطس",@"سبتمبر",@"أكتوبر",@"نوفمبر",@"ديسمبر",nil] autorelease];
        NSArray *eMonths=[[[NSArray alloc] initWithObjects:@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",nil] autorelease];
        months=[[NSDictionary alloc] initWithObjects:aMonths forKeys:eMonths];
    
    }
    
    
    - (void)didReceiveMemoryWarning {
        // Releases the view if it doesn't have a superview.
        [super didReceiveMemoryWarning];
    
        // Release any cached data, images, etc. that aren't in use.
    }
    
    - (void)viewDidUnload {
        [super viewDidUnload];
        // Release any retained subviews of the main view.
        // e.g. self.myOutlet = nil;
    }
    
    
    - (void)dealloc {
        [super dealloc];
        [l release];
        [t release];
        [b release];
        [name release];
        [limit release];
        [str release];
        [target release];
        [numbers release];
        [months release];
        [picker release];
        [actionSheet release];
    }
    
    
    /*§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~
                                        Controls
     §~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~*/
    
    -(IBAction) bPressed{
        [self showPicker];
    }
    
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
        [self showPicker];
        [super touchesBegan:touches withEvent:event];
    }
    
    /*§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~
                                        picker handeling methods
     §~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~*/
    
    -(void) setTarget:(UIView *)tar{
        target=tar;
    }
    
    -(void)showPicker{
        actionSheet = [[UIActionSheet alloc] initWithTitle:@"select a date"
                                                  delegate:self
                                         cancelButtonTitle:nil
                                    destructiveButtonTitle:nil
                                         otherButtonTitles:nil];
    
        picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0,40,0,0)];
        picker.delegate = self;
        picker.showsSelectionIndicator = YES;
        year=[self getYear];
        month=[self getMonth];
        day=[self getDay];
        [picker selectRow:year inComponent:0 animated:NO];
        [picker selectRow:(day+(9300/2)) inComponent:2 animated:NO];
        [picker selectRow:(month-1+(9600/2)) inComponent:1 animated:NO];
        [actionSheet addSubview:picker];
    
        UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"OK"]];
        closeButton.momentary = YES; 
        closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
        closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
        closeButton.tintColor = [UIColor blackColor];
        [closeButton addTarget:self action:@selector(dismissActionSheet) forControlEvents:UIControlEventValueChanged];
        [actionSheet addSubview:closeButton];
        [closeButton release];
    
        [actionSheet showInView:[UIApplication sharedApplication].keyWindow];
        [actionSheet setBounds:CGRectMake(0,0,320,469)];
        actionSheet.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleTopMargin
        |UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleBottomMargin;
        [picker release];
        [actionSheet release];  
    }
    
    
    - (void)changeDateInLabel:(id)sender{
        NSString *m = [[[NSString alloc] initWithFormat:@"%d", (month-1)] autorelease];
        m=[months objectForKey:m];
        NSString *y=[self translateYear:year];
        NSString *d=[self translateYear:day];
        NSString *dat = [NSString stringWithFormat:@"%@ / %@ / %@",d,m,y];
        t.text=dat;
    
        NSDateFormatter *df = [[NSDateFormatter alloc] init];
        [df setDateFormat:@"yyyy-MM-dd"];
        NSString *realStr=[[[NSString alloc] initWithFormat:@"%d-%d-%d",year,month,day+1]autorelease];
        NSDate *realDate = [df dateFromString:realStr];
        [df release];
        NSLog(@"Date: %@", realDate);
        NSString *timestamp = [NSString stringWithFormat:@"%0.0f", [realDate timeIntervalSince1970]];
        NSLog(@"millis: %@", timestamp);
    }
    
    
    -(void)dismissActionSheet{
        [actionSheet dismissWithClickedButtonIndex:0 animated:YES];
    }
    
    
    /*§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~
                                        Date Methods
     §~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~*/
    
    -(int) getYear{
        NSDateComponents *components = [[NSCalendar currentCalendar] components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit fromDate:[NSDate date]];
        return [components year];
    }
    
    -(NSString*)translateYear:(int)iYear{
        NSString *aYear=@"";
        while(iYear>0){
            int r=iYear%10;
            iYear=iYear/10;
            NSString *s = [NSString stringWithFormat:@"%d", r];
            NSString *temp=[numbers objectForKey:s];
            aYear=[temp stringByAppendingString:aYear];
        }
        return aYear;
    }
    
    -(int) getDay{
        NSDateComponents *components = [[NSCalendar currentCalendar] components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit fromDate:[NSDate date]];
        return [components day];    
    }
    
    -(int) getMonth{
        NSDateComponents *components = [[NSCalendar currentCalendar] components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit fromDate:[NSDate date]];
        return [components month];  
    }
    
    -(int)getNumberOfDaysinYear:(int)y andMonth:(int)m{
        NSCalendar* cal = [NSCalendar currentCalendar];
        NSDateComponents* comps = [[[NSDateComponents alloc] init] autorelease];
    
        [comps setMonth:m];
        [comps setYear:y];
    
        NSRange range = [cal rangeOfUnit:NSDayCalendarUnit
                                  inUnit:NSMonthCalendarUnit
                                 forDate:[cal dateFromComponents:comps]];
        return range.length;
    }
    
    
    /*§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~
                                    picker delegate methods
     §~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~§~*/
    
    - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;{
        return 3;
    }
    
    - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
        int d=[self getDay];
        int y=[self getYear];
        int m=[self getMonth];
        day=[picker selectedRowInComponent:2]%31;
        if(day==0){
            day=31;
        }
        month=([picker selectedRowInComponent:1]%12)+1;
        year=[picker selectedRowInComponent:0];
        if(year>y){
            year=y;
            [picker selectRow:y inComponent:0 animated:YES];
            [picker selectRow:(d+(9300/2)) inComponent:2 animated:YES];
            [picker selectRow:(m-1+(9600/2)) inComponent:1 animated:YES];
        }
        else{
            if(month>m && year==y){
                month=m;
                [picker selectRow:(m-1+(9600/2)) inComponent:1 animated:YES];
                [picker selectRow:(d+(9300/2)) inComponent:2 animated:YES];
            }
            else{
                int total=[self getNumberOfDaysinYear:year andMonth:month];
                if((day>total)||(day>d && month==m && year==y)){
                    day=d;
                    [picker selectRow:(d+(9300/2)) inComponent:2 animated:YES];
                }
            }
        }
        [picker reloadComponent:0];
        [picker reloadComponent:1];
        [picker reloadComponent:2];
        [self changeDateInLabel:nil];
    }
    
    - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
        switch (component) {
            case 0:{
                return 4000;
                break;
            }
            case 1:{
                return 12*800;
                break;
            }
            case 2:{
                 return 31*300;
                break;  
            }
            default:{
                return 0;
                break;
            }
        }
    }
    
    - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
        UILabel *pickerLabel = (UILabel *)view;
        if ((pickerLabel == nil) || ([pickerLabel class] != [UILabel class])) { //newlabel
            CGRect frame = CGRectMake(0.0, 0.0, 75, 32.0);
            pickerLabel = [[[UILabel alloc] initWithFrame:frame] autorelease];
            pickerLabel.textAlignment = UITextAlignmentRight;
            pickerLabel.backgroundColor = [UIColor clearColor];
            pickerLabel.font = [UIFont boldSystemFontOfSize:22];
        } 
        switch (component) {
            case 0:{
                [pickerLabel setText:[self translateYear:row]];         
                int y=[self getYear];
                if(row==y){
                    pickerLabel.textColor = [UIColor blueColor];
                }
                else{
                    if(row>y){
                        pickerLabel.textColor = [UIColor grayColor];
                    }
                    else{
                        pickerLabel.textColor = [UIColor blackColor];
                    }
                }
                return pickerLabel;
                break;
            }
            case 1:{
                NSString *sM = [NSString stringWithFormat:@"%d", (row%12)];
                [pickerLabel setText:[months objectForKey:sM]];
                int m=[self getMonth];
                int y=[self getYear];
                if(y<=year){
                    if(((row%12)+1)==m){
                        pickerLabel.textColor = [UIColor blueColor];
                    }
                    else{
                        if(((row%12)+1)>m){
                            pickerLabel.textColor = [UIColor grayColor];
                        }
                        else{
                            pickerLabel.textColor = [UIColor blackColor];
                        }
                    }
                }
                else{
                    if(year<y){
                        if(((row%12)+1)==m){
                            pickerLabel.textColor = [UIColor blueColor];
                        }
                        else{
                            pickerLabel.textColor = [UIColor blackColor];
                        }
                    }
                }
                return pickerLabel;
                break;
            }
            case 2:{
                int r;
                if((row%31)==0){
                    r=31;
                }
                else{
                    r=(row%31);
                }
                [pickerLabel setText:[self translateYear:r]];
                int d=[self getDay];
                int y=[self getYear];
                int m=[self getMonth];
                if(y<=year && m<=month){
                    if(r==d){
                        pickerLabel.textColor = [UIColor blueColor];
                    }
                    else{
                        if(r>d){
                            pickerLabel.textColor = [UIColor grayColor];
                        }
                        else{
                            int total=[self getNumberOfDaysinYear:year andMonth:month];
                            if(r<=total){
                                pickerLabel.textColor = [UIColor blackColor];
                            }
                            else{
                                pickerLabel.textColor = [UIColor grayColor];
                            }
                        }
                    }
                }
                else{
                    if(year<y || month<m){
                        if(r==d){
                            pickerLabel.textColor = [UIColor blueColor];
                        }
                        else{
                            int total=[self getNumberOfDaysinYear:year andMonth:month];
                            if(r<=total){
                                pickerLabel.textColor = [UIColor blackColor];
                            }
                            else{
                                pickerLabel.textColor = [UIColor grayColor];
                            }
                        }
                    }
                }
                return pickerLabel;
                break;  
            }
        }
        return nil;
    }
    
    
    
    
    @end
    

    Thank you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im trying to implement a custom error page, what i want to be able
Found a really nice code for Accordion nav and am trying implement on our
Trying to implement an autocomplete based on this It looks like it's very straight
Trying to implement this gallery on my website. http://coffeescripter.com/code/ad-gallery/ It is noted in the
iam trying to implement an Searchmachine into my site. Iam using Zend_Search_Lucene for this.
Trying to implement a shell, mainly piping. I've written this test case which I
Im trying to implement some code i found on a website which duplicates a
Im trying to implement a UnitofWork pattern using this Scott Allen tutorial My current
I am doing an application where I am trying to implement the arabic style
I'm trying implement pull to refresh on a ListFragment but right now none of

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.