2010-05-17 57 views
1

我在一個數據庫(CoreData)中使用一個與多個組件相關的pickerView。 根據數據庫中數據的存在情況,是否可以更改特定組件的fontcolor? 例如,數據庫中的字段爲空,組件字體顏色應該是RED,否則爲黑色。UiPickerView根據數據改變字體顏色

任何幫助將不勝感激!

達里奧

================== 感謝肯尼,

我必須只適用於單一的UIPicker。所以我',返回視圖parametere(沒有modificatiosn)。結果是所有挑選者顯示空行。

感謝您的幫助!

你會發現這裏的代碼片段:

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

if (pickerView == tipoPk){ 
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100,30)]; 
label.textColor =  [UIColor redColor]; 
switch (component) { 
case PK_Tipo: 
label.text = [tipoArray objectAtIndex:row]]; 
break; 
case PK_Settore: 
label.text = [settoreArray objectAtIndex:row]]; 
break; 
default: 
break; 
} 
return label; 
} 
else { 
return view; // <==== return view for non related pickerviews , but no rows shown 
} 


} 

回答

0

是的,但你必須使用-pickerView:viewForRow:forComponent:reusingView:並提供自定義的UILabel。

4

這一個也適用..

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

CGRect imageFrame = CGRectMake(0.0, 0.0, 15, 15); 
UIImageView *label = [[[UIImageView alloc] initWithFrame:imageFrame] **autorelease**]; 

if (row == 0) 
{ 
    label.backgroundColor = [UIColor redColor]; 
} 
if (row == 1) 
{ 
    label.backgroundColor = [UIColor blueColor]; 
} 
if (row == 2) 
{ 
    label.backgroundColor = [UIColor blackColor]; 
} 
return label; 

}