2010-11-26 56 views
7

我有UIPickerView與兩列,並在一列中我想顯示旁邊的圖像和標籤。有用。顯示和圖像和標籤,只是標籤下圖像如何把圖像放在左邊,並在右邊標籤?我試圖將標籤對齊到正確的位置,但它不起作用。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 2010-11-26 10:23:22