首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有Actionsheet的iPhone DatePicker

带有Actionsheet的iPhone DatePicker
EN

Stack Overflow用户
提问于 2012-01-20 00:56:58
回答 3查看 3K关注 0票数 1

我使用这段代码来显示一个datePicker。当单击某个textField时,它会出现。但是,"close“按钮会覆盖DatePicker。你知道有什么方法可以把它调低一点吗?提前谢谢。

代码语言:javascript
复制
-(IBAction)acsheet:(id)sender{

actionSheet = [[UIActionSheet alloc] initWithTitle:nil 
                                          delegate:nil
                                 cancelButtonTitle:nil
                            destructiveButtonTitle:nil
                                 otherButtonTitles:nil];

[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];

//CGRect pickerFrame = CGRectMake(0, 45, 0, 0);
pickerView1 = [[UIDatePicker alloc] init];
pickerView1.datePickerMode = UIDatePickerModeDate;  



[actionSheet addSubview:pickerView1];

UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Close"]];
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];
[actionSheet showInView:[[UIApplication sharedApplication] keyWindow]];    
[actionSheet setBounds:CGRectMake(0, 0, 320, 485)];

[pickerView1 addTarget:self
             action:@selector(updateLabel:)
     forControlEvents:UIControlEventValueChanged]; 
UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismissDatePicker:)] ;
UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height, 320, 44)];
toolBar.tag = 11;
toolBar.barStyle = UIBarStyleBlackTranslucent;

[toolBar setItems:[NSArray arrayWithObjects:spacer, doneButton, nil]];
[self.view addSubview:toolBar];



}
EN

回答 3

Stack Overflow用户

发布于 2012-01-20 01:56:37

如果希望在UITextField成为第一响应者时显示UIDatePicker,则应将日期选择器设置为文本字段的inputView。然后,当您点击字段时,日期选择器将向上滑动,而不是键盘。

票数 8
EN

Stack Overflow用户

发布于 2012-01-20 01:01:29

代码语言:javascript
复制
closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);

7.0f30.f更改为更积极的values.and,然后尝试。

7.0f值是按钮// increase it to shift the button lower的原始.y

30.f值是按钮// increase it by the same amount you increase origin to keep proportional height的size.height

票数 1
EN

Stack Overflow用户

发布于 2012-01-20 17:30:44

我已经自己锻炼过了;

我已经更改了这一行:

代码语言:javascript
复制
  pickerView1 = [[UIDatePicker alloc] init];

如下所示:

代码语言:javascript
复制
pickerView1 = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 40, 320, 450)];
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8930052

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档