请帮助我在iPhone应用程序的按钮点击时获得UIDatePicker
到UILabel
的值。
答案 0 :(得分:10)
创建一个插座,然后只询问其值
-(IBAction)OnButtonClick:(id)sender
{
NSDate *date = datePicker.date;
label.text = [date description];
}
答案 1 :(得分:0)
DatePicker=[[UIDatePicker alloc]init];
[DatePicker setDatePickerMode:UIDatePickerModeDate];
//[DatePicker setMaximumDate:[NSDate date]];
[DatePicker setMinimumDate:[NSDate date]];
[DatePicker addTarget:self action:@selector(updateDate:)
forControlEvents:UIControlEventValueChanged];
-(void) doneButton
{
[self updateDate:DatePicker]; //calling this fuction on inside the button
}
-(void)updateDate:(UIDatePicker *)sender
{
NSDate *date = self.DatePicker.date;
_dateFormat = [[NSDateFormatter alloc]init];
[_dateFormat setDateFormat:@"MM/dd/yyyy"];
DateTextField.text = [_dateFormat stringFromDate:date];
}
答案 2 :(得分:0)
Swift 2.0
@IBAction func buttonPressed(sender: AnyObject) {
let date: NSDate = timePicker.date
label.text = date.description
}