2017-05-17 8 views
1

私は、storyboardのスクリーンショットに示されているようにUIPickerViewUIDatePickerviewControllerを持っています。 The screenshot from my storyboard hereの説明に従ってランタイム属性を追加しようとしました。しかしそれに続くのは、最初に強調表示されたテキストのフォント色を変更するだけでした。 私は両方のpickerViewとdatePickerのテキストの色を白に変更したいと思います。私はそれをどのように達成できるのか分からない。UIPickerViewとUIDatePickerのフォントの色を変更するにはどうすればよいですか?

答えて

3

self.datePicker.setValue(UIColor.white, forKeyPath: "textColor") 

それは

そしてPickeViewために、あなたが好き起因する文字列を設定する必要がUIDatePickerのtextcolorは変化します、

func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? { 

    return NSAttributedString(string: "Your Text", attributes: [NSForegroundColorAttributeName:UIColor.blue]) 
} 
1

はあなたがフォントを変更することはできませんUIDatePickerについては「UIPickerView」

func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView!) -> UIView { 
    // Your custom view with custom font here 
} 

のために「viewForRow」デリゲートメソッドを使用することができますが、の、textColorを変更するには、このコードを使用することができます。

datePicker.setValue(UIColor.whiteColor(), forKeyPath: "textColor") 
datePicker.datePickerMode = .CountDownTimer 
datePicker.datePickerMode = .DateAndTime 

これが役立ちます。

-1

ピッカービューのattributedTitleForRowデリゲートメソッドを使用して色を変更できます。このリンクHow do I change the color of the text in a UIPickerView under iOS 7?を参照してください。また、viewForRowデリゲートメソッドを使用して、カスタムUILabelをビューとして追加することもできます。日付ピッカーのテキストの色を変更するには、この行を記述する必要が

+0

これは私が参考にした質問と同じです。 – amagain

+0

あなたの答えが得られましたか? @amagain – jegadeesh

2

この2行で私の1日が保存されました。

NepaliDatePicker.setValue(UIColor.white, forKey: "textColor") 
    EnglishDatePicker.setValue(UIColor.white, forKey: "textColor") 
関連する問題