2016-04-08 10 views
2

UIPickerViewを、各コンポーネントごとにハードコードされたテキストで表示したいとします。 "Hours"と "Mins"のようなもの。これを実現するには、ラベルを作成して、サブビューとしてピッカービューに配置します。これは上記のiOS 7 &で問題なく動作します。iOS 6の各コンポーネントのUIPickerView固定ラベルの問題

しかし、iOS 6の場合、私のラベルはUIPickerViewのコンポーネントで重複しているため、表示されません。 iOS 6ではどのようにしてこのビューを実現できますか。各コンポーネントでは、値が固定ラベルにタグ付けされているため、ユーザーは選択した内容を知ることができます。

+1

なぜこの時点でiOS 6をサポートしようとしているのか不思議です。この時点でこれは時代遅れです。 iOS 7以降とはまったく異なるルック&フィールを備えています。 – rmaddy

+0

クライアントはまだiOS 6を使用しているため、サポートが必要です。 – Abhinav

+0

ラベルをピッカービューの上に置くだけです。 – rmaddy

答えて

0

、これは(カエルの提案に基づいて)私はこれを達成する方法である:

- (void)setDatePickerView:(MyCustomCell *)iCell { 
    UIView *inputView = [[UIView alloc] init]; 

    // Add Picker First 
    UIPickerView *pickerView = [[UIPickerView alloc] init]; 
    pickerView.delegate = self; 
    pickerView.tag = 100; 

    int height = 30; 
    int offsetY = pickerView.frame.size.height/2 - height/2; 

    // Add a line on top of selection 
    if ([Utilities isIOS7orAbove]) { 
     UIImageView *topLineView = [[UIImageView alloc] initWithFrame:CGRectMake(0, offsetY - 2, pickerView.frame.size.width, 1)]; 
     [topLineView setBackgroundColor:[UIColor grayColor]]; 
     [pickerView addSubview:topLineView]; 
    } 

    [inputView addSubview:pickerView]; 

    // Add Minute Label 
    CGFloat minLabelX = [Utilities isIOS7orAbove] ? 97 : 90; 
    CGFloat labelYM = [Utilities isIOS7orAbove] ? 0.0 : 1.0; 
    CGFloat labelW = 50; 

    UILabel *minutesLabel = [[UILabel alloc] initWithFrame:CGRectMake(minLabelX, offsetY - labelYM, labelW, height)]; 
    minutesLabel.text = @“Mins"; 
    minutesLabel.font = [UIFont systemFontOfSize:kFontSize22]; 
    minutesLabel.backgroundColor = [UIColor clearColor]; 
    minutesLabel.textColor = [UIColor blackColor]; 
    [inputView addSubview:minutesLabel]; 

    // Now Add Seconds Label 
    CGFloat secLabelX = [Utilities isIOS7orAbove] ? 230 : 218; 
    UILabel *secondsLabel = [[UILabel alloc] initWithFrame:CGRectMake(secLabelX, offsetY - labelYM, labelW, height)]; 
    secondsLabel.text = @“Secs"; 
    secondsLabel.font = [UIFont systemFontOfSize:kFontSize22]; 
    secondsLabel.backgroundColor = [UIColor clearColor]; 
    secondsLabel.textColor = [UIColor blackColor]; 
    [inputView addSubview:secondsLabel]; 

    iCell.inputField.inputView = inputView; 
} 
2

私はあなたがピッカーのビューとラベルを含むカスタムビューを作成することでこれを達成できると思います。他人の利益のために

+0

はい、解決策のように思えます。私はそれを試してみましょう。 – Abhinav

0

だけActionSheetPicker3.0を使用し、私はそれを私がカスタムピッカーを必要とするすべての時間を使用します。これはiOS6 +で完全に動作します。

これは文字列のピッカーのためにそれを使用する方法である:

NSArray *colors = [NSArray arrayWithObjects:@"Hours", @"Mins", @"Whatever", @"More", nil]; 

[ActionSheetStringPicker showPickerWithTitle:@"Select a Color" 
             rows:colors 
          initialSelection:0 
            doneBlock:^(ActionSheetStringPicker *picker, NSInteger selectedIndex, id selectedValue) { 
             NSLog(@"Picker: %@, Index: %@, value: %@", 
             picker, selectedIndex, selectedValue); 
            } 
           cancelBlock:^(ActionSheetStringPicker *picker) { 
             NSLog(@"Block Picker Canceled"); 
            } 
             origin:sender]; 

お楽しみください!

関連する問題