【问题标题】:Change TextColor while scrolling in PickerView在 PickerView 中滚动时更改 TextColor
【发布时间】: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


【解决方案1】:

您可以在示例中使用多个 PickerView 来实现所需的效果,即中心的主 PickerView 具有大字体和不同的颜色。然后在上方和下方放置两个较小的选取器视图,确保所有这些视图的大小都受到限制,以便只有一个行高可见。确保仅设置主对象的委托并将其在视图层次结构中向前移动,当手动滚动时会偏移其他选择器的内容。

【讨论】:

  • 感谢您的回答。但我对 “确保仅设置主对象的委托并将其在视图层次结构中向前移动,当手动滚动时偏移其他选择器的内容时​​感到困惑。” 我是没有得到这个,对不起
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-03-12
  • 2011-05-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-30
  • 2020-06-29
相关资源
最近更新 更多