Question

I need to add time picker to system settings for my app, Is it possible? I see there is a UITextField but no property with time picker for the UITextField.

Was it helpful?

Solution

You have UIPickerView for showing picker UITextFieldDelegates for textfield start editing

On click on textfield

  • Disable Keyboard
  • Show picker
  • On picker delegate set the textfield with selected value

Edit : In case of settings page which is managed with a plist.It is impossible to do so since apple doesnt give such wide support on the setings page.You van add settings to the application itself as a setting page and do all this

OTHER TIPS

Initialize a textfield. for example UITextField *txtFld;

//Text Field delegate method
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
     [textField resignFirstResponder];
     UIDatePicker *datePicker = [[UIDatePicker alloc]initWithFrame:FRAME];
     datePicker.datePickerMode = UIDatePickerModeTime;
     [datePicker addTarget:self action:@selector(changeTextFieldValue:) forControlEvents:UIControlEventValueChanged];
     [self.view addSubview:datePicker];
}

-(void)changeTextFieldValue:(id)sender
{
    NSDate *date = [datePicker date];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
    [dateFormatter setDateFormat:@"hh-mm"];
    NSString *dateString = [dateFormatter stringFromDate:date ];
    txtFld.text = dateString;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top