2017-12-18 13 views
2

Swift 3.2を使用しているmacOSプロジェクトでは、UITextViewのフォアグラウンドカラーを設定しようとしています。MacOSで 'foregroundColor'を設定するとエラーが発生する

let placeHolderTitleString: NSAttributedString = NSAttributedString(string: "Enter text here", attributes: [NSAttributedStringKey.foregroundColor : NSColor.gray]) // error 

私が手にエラーがこれです:

タイプ 'NSAttributedStringKey'(別名 'NSStringのは、')何のメンバー 'foregroundColor'

同じコードがで正常に動作していませんSwift 4.0プロジェクト。

私はiOS Swift 4 Conversion error - NSAttributedStringKey: Anyで見つかったいくつかの回答に基づいてコードを修正しようとしていますが、引き続きエラーが発生します。プロジェクトをSwift 4にアップデートすることなくこれを修正する方法はありますか?

答えて

5

スイフト3は、新しいスウィフト4 NSAttributeStringKeyの値を使用しません。

フォアグラウンドカラーの使用NSForegroundColorAttributeName

let placeHolderTitleString: NSAttributedString = 
    NSAttributedString(string: "Enter text here", attributes: 
    [NSForegroundColorAttributeName : NSColor.gray]) 
+0

がうまく働いた、rmaddyありがとう。 – Cue

関連する問題