2016-03-28 32 views
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]; 
} 

我怎样才能做到这一点?

enter image description here

回答

0

你可以实现你的榜样所期望的效果与多个PickerViews即与大类型和颜色区分中心的主PickerView。然后在上面和下面放置两个较小的选取器视图,确保所有这些视图的大小都受到限制,以便只显示一行高度。确保只设置主对象的委托,并在View层次结构中将其向前移动,手动滚动时会偏移其他选取器的内容。

+0

感谢您的回答。但我很迷惑**“确保只设置主对象的代理并将其在View层次结构中向前移动,手动滚动时将其他拾取器的内容偏移。”** 我不是得到这个,对不起 – user2526811