2016-03-28 33 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