UiPickerView根据数据更改字体颜色 [英] UiPickerView change font color according data

查看:379
本文介绍了UiPickerView根据数据更改字体颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的pickerView具有与数据库(CoreData)的多个字段相关的多个组件。
是否可以根据数据库中数据的存在来更改特定组件的字体颜色?
例如,数据库中的字段为空,组件字体颜色应为红色,否则为黑色。

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.

任何帮助将不胜感激!

达里奥

==================
感谢肯尼,

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

我只能申请一个UIPicker。因此,我返回了视图参数(无修改)。结果是所有选择器都显示空行。

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.

感谢帮助!

在这里您将找到代码片段:

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
}  


}


推荐答案

此方法也适用。.

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

}

这篇关于UiPickerView根据数据更改字体颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆