将 UIDatePicker 装入 UIActionSheet [英] Fitting a UIDatePicker into a UIActionSheet

查看:15
本文介绍了将 UIDatePicker 装入 UIActionSheet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让一个带有 UIButton 的 UIDatePicker 显示在 UIActionSheet 中.不幸的是,它被裁剪掉了,整个日期选择器不可见.我什至还没有尝试添加 UIButton.任何人都可以建议让整个视图正确适合吗?我不确定如何添加适当的维度,因为 UIActionSheet 似乎缺少 -initWithFrame: 类型构造函数.

I'm trying to get a UIDatePicker with a UIButton to show up in a UIActionSheet. Unfortunately it gets cropped off and the entire Date Picker is not visible. I have not even attempted to add the UIButton yet. Can anyone suggest on getting the entire view to fit properly? I'm not sure how to add the proper dimensions as UIActionSheet seems to lack an -initWithFrame: type constructor.

UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:@"Date Picker" 
                                                  delegate:self
                                         cancelButtonTitle:@"Cancel"
                                    destructiveButtonTitle:nil
                                         otherButtonTitles:nil];

// Add the picker
UIDatePicker *pickerView = [[UIDatePicker alloc] init];
pickerView.datePickerMode = UIDatePickerModeDate;
[menu addSubview:pickerView];
[menu showInView:self.view];

[pickerView release];
[menu release];

我也尝试过类似的东西:

I've also tried with something similar to:

UIActionSheet *menu = [[UIActionSheet alloc] initWithFrame:CGRectMake(200.0, 200.0, 100.0f, 100.0f)];

坐标当然不现实,但它们似乎不会影响 UIActionSheet 的位置/大小.

The coords are ofcourse not realistic, but they don't seem to affect the position/size of the UIActionSheet.

推荐答案

你可以这样使用(调整坐标):

You can use something like this (adjust the coordinates):

    UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:@"Date Picker" 
                                                  delegate:self
                                         cancelButtonTitle:@"Cancel"
                                    destructiveButtonTitle:nil
                                         otherButtonTitles:nil];

    // Add the picker
    UIDatePicker *pickerView = [[UIDatePicker alloc] init];
    pickerView.datePickerMode = UIDatePickerModeDate;
    [menu addSubview:pickerView];
    [menu showInView:self.view];    
    [menu setBounds:CGRectMake(0,0,320, 500)];

    CGRect pickerRect = pickerView.bounds;
    pickerRect.origin.y = -100;
    pickerView.bounds = pickerRect;

    [pickerView release];
    [menu release];

但是你最好创建一个带有 UIDatePicker 和导航栏的全屏视图.有关示例,请参阅 UICatalog -> iPhone DevCenter 中的 Pickers 示例.

But you better create a fullscreen view with a UIDatePicker and a navigation bar. For an example see UICatalog -> Pickers sample from the iPhone DevCenter.

这篇关于将 UIDatePicker 装入 UIActionSheet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆