gpt4 book ai didi

iphone - 更改特定行颜色 uipicker

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:49:14 30 4
gpt4 key购买 nike

我有以下问题:我可以更改 uipicker 中各行的文本颜色,但不能更改我想要的特定行的文本颜色,选择器变得很困惑,很多文本标签变成蓝色。

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
UILabel *retval = (UILabel*)view;
if (!retval) {
retval= [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [pickerView rowSizeForComponent:component].width, [pickerView rowSizeForComponent:component].height)];
}
retval.text = [arraySubSistemasDeSaude objectAtIndex:row];
if(pickerView == subSistemaSaudePicker) {

if ([retval.text isEqualToString:@"Seguros de saúde"]) {

NSLog(@"ROW=%d",row);
[retval setTextColor:[UIColor blueColor]];
}
if ([retval.text isEqualToString:@"Sistemas de Saúde e Equiparados"]) {
NSLog(@"ROW=%d",row);
[retval setTextColor:[UIColor blueColor]];

if ([retval.text isEqualToString:@"Seguradoras-Acidentes de Trabalho, viação/pessoais e vida"]) {
NSLog(@"ROW=%d",row);
[retval setTextColor:[UIColor blueColor]];
}
if ([retval.text isEqualToString:@"Empresas, associações e outras entidades"]) {
NSLog(@"ROW=%d",row);

[retval setTextColor:[UIColor blueColor]];

}


[retval setBackgroundColor:[UIColor clearColor]];
retval.font = [UIFont systemFontOfSize:14];

}

} else if(pickerView == horarioPicker) {
retval.text =[arrayHorarios objectAtIndex:row];
[retval setBackgroundColor:[UIColor clearColor]];
retval.font = [UIFont systemFontOfSize:14];

} else if(pickerView == examesPicker) {
retval.text =[arrayExames objectAtIndex:row];
[retval setBackgroundColor:[UIColor clearColor]];
retval.font = [UIFont systemFontOfSize:14];

} else if(pickerView == consultasPicker) {
retval.text =[arrayConsultas objectAtIndex:row];
[retval setBackgroundColor:[UIColor clearColor]];
retval.font = [UIFont systemFontOfSize:14];

}else {
assert(NO);
}
return retval;
}

抱歉我的英语不好,我希望我能把问题说清楚,在此先感谢。

最佳答案

问题是,您正在为每一行重复使用 View ,并且您没有将 UILabel 颜色设置回黑色,因为它不应该是蓝色。

添加这段代码...

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
UILabel *retval = (UILabel*)view;
if (!retval) {
retval= [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [pickerView rowSizeForComponent:component].width, [pickerView rowSizeForComponent:component].height)];
}
[retval setTextColor:[UIColor blackColor]];
retval.text = [arraySubSistemasDeSaude objectAtIndex:row];
......

有了这个,每次它拉出一个重复使用的 View 时,它都会首先将颜色设置为黑色。然后代码将检查您想要的蓝色并将它们设置为蓝色。你这样做的方式是,将其中一些设置为蓝色,然后当你重新使用它们时,你永远不会将其重置为黑色。

关于iphone - 更改特定行颜色 uipicker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11797595/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com