1
我想更改选取器视图的TextColor。调用didSelectRow
方法后,我可以更改textColor。在PickerView中滚动时更改TextColor
但是我想改变TextColor,当文本来到selectedRow区域,就像iPhone中的时钟应用程序一样。
mycode的:
-(NSAttributedString*)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component
{
NSAttributedString *str= [[NSAttributedString alloc]initWithString:[NSString stringWithFormat:@"%02ld",row] attributes:@{
NSForegroundColorAttributeName:[UIColor redColor]
}];
if([pic selectedRowInComponent:component]==row)
str= [[NSAttributedString alloc]initWithString:[NSString stringWithFormat:@"%02ld",row] attributes:@{
NSForegroundColorAttributeName:[UIColor greenColor]
}];
return str;
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
[pic reloadComponent:component];
}
我怎样才能做到这一点?
感谢您的回答。但我很迷惑**“确保只设置主对象的代理并将其在View层次结构中向前移动,手动滚动时将其他拾取器的内容偏移。”** 我不是得到这个,对不起 – user2526811