【发布时间】:2016-07-15 18:20:25
【问题描述】:
我想更改选取器视图的 TextColor。我可以在调用 didSelectRow 方法后更改 textColor。
但是当文本进入 selectedRow 区域时,我也想更改 TextColor,就像 iPhone 中的时钟应用程序一样。
我的代码:
-(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];
}
我怎样才能做到这一点?
【问题讨论】:
-
你管理好了吗??
标签: ios iphone xcode uiscrollview datepicker