简体   繁体   中英

UiPickerView change font color according data

I'm using a pickerView with multiple components related to several fields in a Database (CoreData). Is it possible to change the fontcolor for a specific component according the presence of data in the DB ? For example the field in the DB is null the component font color should be RED otherwise black.

Any help will be appreciated !

Dario

================== Thanks Kenny,

I have to apply to a single UIPicker only. So I', returning the view parametere (without modificatiosn). The result is all the pickers show empty rows.

Thanks for help !

Here you will find the code fragment:

  - (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
}  


}

This one also works..

- (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;

}

是的,但您必须使用-pickerView:viewForRow:forComponent:reusingView:并提供自定义UILabel。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM