objective-c - 将 UIDatePicker 装入 UIActionSheet

标签 objective-c iphone cocoa-touch uidatepicker

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

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];

我也尝试过类似的东西:

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

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

最佳答案

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

    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 和导航栏创建全屏 View 。有关示例,请参阅 iPhone DevCenter 中的 UICatalog -> Pickers 示例。

关于objective-c - 将 UIDatePicker 装入 UIActionSheet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/349858/

相关文章:

cocoa - 如何在cocoa中绘制直方图

iphone - 吉他英雄型节拍器

ios - 如何在 iOS 中设置文本格式

ios - 如何使用 OWA(Outlook Web Access) 访问 Microsoft Exchange 邮件

ios - 带有错误映射的 RestKit PUT 请求

iphone - 为 iPhone 应用程序生成类图

iphone - 应用程序在 3GS 上速度很快,但在 3G 上速度很慢

ios - 具有 "multiple"个代表的 UITextField

iphone - 在UITextView中以编程方式编写文本

objective-c - 如何使用 Objective-C 加载 dylib 或 .a(静态库)文件?