自定义UIPickerView

时间:2012-04-12 09:25:06

标签: ios uipickerview

我正在尝试创建自定义UIPickerView,如下所示......:

http://img824.imageshack.us/img824/3015/pickercustom.png

示例: 从“8h15”到“12h15”

我对这个概念完全失明。

请帮助我......任何想法,想法都会受到赞赏。

6 个答案:

答案 0 :(得分:1)

答案 1 :(得分:1)

它可能不是DatePicker,它可能是UIPickerView的一个实例,它的配置方式如下:

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIPickerView_Class/Reference/UIPickerView.html

答案 2 :(得分:0)

使用UIDatePicker无法做到这一点。请改用PickerView。您可以连续显示“8h15”到“12h15”。

答案 3 :(得分:0)

您可以将UIPickerView控件与3段一起使用。填充每个细分的预定义数据。

答案 4 :(得分:0)

您必须自定义UIPickerView。要选择小时,您应该使用您想要的值/标题创建两个数组。

    UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(22, 170, 275, 217)];
    pickerView.delegate = self;
    pickerView.dataSource = self;
    pickerView.showsSelectionIndicator = YES;
    pickerView.opaque = NO;
    [self.view addSubview:pickerView];
    [pickerView release];

和委托方法

    - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView {

return 3;
    }

   - (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:    (NSInteger)component {
NSInteger count =   0;
switch (component) {
    case 0:
        count   =   [arrayHours1 count];
        break;
            case 1:
                    count   =       1;
    case 2:
        count   =   [arrayHours2 count];
        break;
}
return count;
    }

    - (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
NSString *title =   @"";
switch (component) {
    case 0:
        title =  [arrayHours1 objectAtIndex:row];
        break;
    case 2:
        title   =   [arrayHours2 objectAtIndex:row];
        break;
}
return title;

    }

希望这有帮助!

答案 5 :(得分:0)

你可以查一下: -

代码

NSDate * choosen = datePickerView。日期;

        NSDateFormatter *formatter = [[NSDateFormatter alloc]init];

        [formatter setDateFormat:@"yyyy-MM-dd"];

        //[formatter setDateFormat:@"dd-MM-yyyy"];

        NSString *weekday = [formatter stringFromDate:choosen];

        invoiveDateTxtFld.text = [[NSString alloc] initWithFormat:@"%@", weekday];