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