2016-03-28 5 views
1

ピッカービューのTextColorを変更したいとします。私はdidSelectRowメソッドが呼び出された後にtextColorを変更することができます。PickerViewでスクロールするときにTextColorを変更します。

しかし、iPhoneの時計アプリと同じように、テキストがselectedRowエリアに入っているときにもTextColorを変更したいと思います。

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

あなたはすなわち、大タイプと差別色で中心部の主要PickerView複数PickerViewsとあなたの例では所望の効果を得ることができました。次に、2つの小さなピッカービューを上下に配置します。これらのすべてのサイズが制限されていることを確認して、1つの行の高さだけが表示されるようにします。メインオブジェクトのデリゲートのみを設定し、手動でスクロールするときは、他のピッカーの内容をオフセットして、ビュー階層内に配置してください。

+0

あなたの答えをありがとう。しかし、私は** "主オブジェクトのデリゲートを設定して、ビュー階層内でそれを前方に持ってきて、手動でスクロールすると他のピッカーのコンテンツをオフセットしてください" **と混同しています。** 私はいませんこれを得る、ごめんなさい – user2526811

関連する問題