gpt4 book ai didi

ios - 如何在UITextField下动态添加DatePicker

转载 作者:行者123 更新时间:2023-11-29 01:52:31 26 4
gpt4 key购买 nike

我不确定它是否能够在点击时在 UITextField 下动态添加 DatePicker。如果可能,请帮助我显示示例代码。

最佳答案

在文本字段上设置的点击事件

- (void)viewDidLoad {
[super viewDidLoad];

[textField addTarget:self action:@selector(clicked:) forControlEvents:UIControlEventEditingDidBegin];
}

设置文本字段版本为假

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
return NO;
}

点击文本框时的方法

 -(IBAction)clicked:(id)sender
{
[sender resignFirstResponder];
picker1 = [[UIDatePicker alloc] initWithFrame:CGRectMake(textField.frame.origin.x-40, textField.frame.origin.y+textField.frame.size.height, textField.frame.size.width, 200)];
[picker1 setDatePickerMode:UIDatePickerModeDate];
picker1.backgroundColor = [UIColor whiteColor];
[picker1 addTarget:self action:@selector(startDateSelected:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:picker1];
}

当日期值改变时调用此方法

-(IBAction)startDateSelected:(id)sender
{
NSLog(@"%@",picker1.date);
[textField setText:[NSString stringWithFormat:@"%@",picker1.date
]];
}

希望对您有所帮助! :)

关于ios - 如何在UITextField下动态添加DatePicker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31261462/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com