[英]How to create a UIDatePicker on the bottom of the screen and collect the data?
This is two questions.. 这是两个问题。
Here is my code for when I add the date picker: 这是我添加日期选择器时的代码:
picker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
[picker addTarget:self action:@selector(customDate:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:picker];
and here is my customDate:
function 这是我的
customDate:
函数
- (void)customDate:(id)sender {
}
so... what do I do? 所以...我该怎么办? How do I do this?
我该怎么做呢?
Should look something like this: 应该看起来像这样:
- (void) customDate:(id)sender{
NSLocale *usLocale = [[NSLocale alloc]
initWithLocaleIdentifier:@"en_US"];
NSDate *pickerDate = [picker date];
NSString *selectionString = [[NSString alloc] initWithFormat:@"%@",
[pickerDate descriptionWithLocale:usLocale]];
//do something with the date string
}
Put what you need to do in there with the string, whether it be set a label or whatever. 不管是否设置标签,都可以在字符串中放入所需的内容。
And to set the frame: 并设置框架:
picker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 250, 320, 100)];
The numbers there signify the location and size of the date picker, so it goes (x location, y location, width, height) 那里的数字表示日期选择器的位置和大小,因此(x位置,y位置,宽度,高度)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.