2010-11-26 10 views
7

2つの列を持つUIPickerViewがあり、1つの列に画像とラベルを表示したい。できます。表示と画像とラベル、ちょうどラベルはイメージの下にどのようにイメージを左に置いて、ラベルを右側に置いていますか?私は右にラベルの整列を変更しようとしましたが、それは動作しません。UIPickerviewコンポーネントのラベル付き画像

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row 
       forComponent:(NSInteger)component reusingView:(UIView *)view 
    { 
     if(component == kStateComponent) 
     { 
     UIImage *img = [UIImage imageNamed:@"rts1.png"]; 
     UIImageView *temp = [[UIImageView alloc] initWithImage:img];   
     temp.frame = CGRectMake(0, 0, 29, 29); 


      UILabel *channelLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 60, 60)]; 
      channelLabel.text = @"sdfsdfdsf"; 
      channelLabel.textAlignment = UITextAlignmentLeft; 
      channelLabel.backgroundColor = [UIColor clearColor]; 

UIView *tmpView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 110, 60)]; 
          [tmpView insertSubview:temp atIndex:0]; 
          [tmpView insertSubview:channelLabel atIndex:1]; 
      return tmpView; 
     } 
    ... 
    } 

答えて

7

channelLabelに適切なフレームを設定します。例えば、ImageViewのの左に配置し、正しいフレームの原点は、X(CGRectMake関数の第一パラメータ)の座標値を設定するには:

UILabel *channelLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 0, 60, 60)]; 
+0

どうもありがとう:)そして、もう一つ質問がuipickerviewコンポーネントのリストを作るためにどのような方法があるがその中のアイテムを繰り返す。たとえば、最初のアイテムを再び表示するために10日後に10個のアイテムがある場合などです。品質チュートリアルはありますか? – 1110

+0

たとえば、この質問を参照してください:http://stackoverflow.com/questions/214441/how-do-you-make-an-uipickerview-component-wrap-around – Vladimir