iphone - 更改特定行颜色 uipicker
<p><p>我有以下问题:我可以更改 uipicker 内行的文本颜色,但不能更改我想要的特定行的文本颜色,选择器会变得困惑,很多文本标签变成蓝色。</p >
<pre><code>- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
UILabel *retval = (UILabel*)view;
if (!retval) {
retval= [ initWithFrame:CGRectMake(0.0f, 0.0f, .width, .height)];
}
retval.text = ;
if(pickerView == subSistemaSaudePicker) {
if () {
NSLog(@"ROW=%d",row);
];
}
if () {
NSLog(@"ROW=%d",row);
];
if () {
NSLog(@"ROW=%d",row);
];
}
if () {
NSLog(@"ROW=%d",row);
];
}
];
retval.font = ;
}
} else if(pickerView == horarioPicker) {
retval.text =;
];
retval.font = ;
} else if(pickerView == examesPicker) {
retval.text =;
];
retval.font = ;
} else if(pickerView == consultasPicker) {
retval.text =;
];
retval.font = ;
}else {
assert(NO);
}
return retval;
}
</code></pre>
<p>对不起,我的英语不好,我希望我能清楚地回答这个问题,提前谢谢。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>问题是,您正在重用每一行的 View ,并且当 UILabel 颜色不应该是蓝色时,您没有将其设置回黑色。</p>
<p>添加此代码...</p>
<pre><code>- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
UILabel *retval = (UILabel*)view;
if (!retval) {
retval= [ initWithFrame:CGRectMake(0.0f, 0.0f, .width, .height)];
}
];
retval.text = ;
......
</code></pre>
<p>这样,每次它拉出一个重复使用的 View 时,它都会首先将颜色设置为黑色。然后代码将检查您想要的蓝色并将它们设置为蓝色。你这样做的方式是在其中一些上设置蓝色,然后当你重新使用它们时,你永远不会将它重置为黑色。</p></p>
<p style="font-size: 20px;">关于iphone - 更改特定行颜色 uipicker,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/11797595/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/11797595/
</a>
</p>
页:
[1]