2012-04-18 85 views
0

我想在以下設計中使用UIPickerView;UIPickerView的自定義外觀和感覺;

http://dl.dropbox.com/u/53051470/Screen%20shot%202012-04-18%20at%2012.02.36%20PM.png (對不起,作爲一個新的用戶,不能粘貼在這裏圖像)

我讀同一主題的其他問題也和嘗試實施 pickerView:viewForRow:forComponent:reusingView: 方法也沒有得到實際的結果;

需求類似於選定的值應該顯示在帶有複選標記圖像的綠色欄中,並且以白色顯示;此外,當用戶開始滾動選擇器時,任何進入綠色條內的值都會變成綠色,任何離開綠色條的值都會變成黑色;

有什麼建議嗎?

親切的問候;

回答

0

你應該使用方法

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view 

,並決定哪一行是突出

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view 
{ 
     // i use a UILabel instead of your **custom UIView** , you may add a tick in you custom view 

     UILabel *testRow = view?(UILabel *)view:[[[UILabel alloc] initWithFrame:CGRectMake(0,0, 140, 40)] autorelease]; 
     testRow.font = [UIFont fontWithName:[testArray objectAtIndex:row] size:16]; 
     testRow.text = [fontsArray objectAtIndex:row]; 
     testRow.backgroundColor = [UIColor clearColor]; 

     if (row == selectedRow) 
     { 
      testRow.backgroundColor = [UIColor greenColor]; 
     } 

     return testRow; 
} 

不要忘記showsSelectionIndicator設置爲NO

pickView.showsSelectionIndicator = NO; 
0

UIPickerView多重選擇 - 行爲而不在pickerview前添加其他視圖,使用:https://github.com/alexleutgoeb/ALPickerView

改進非常感謝!

+0

我想我不是在討論UIPickerView的多選行爲;如果你提到的庫可以創建一個具有所需設計的選擇器,那麼從那裏發佈一些示例代碼; – Ans 2012-04-19 05:41:47

+0

您從該庫的左上角的該鏈接下載了該zip文件可用的代碼。 – 2012-04-19 06:13:17