2017-12-18 14 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의'

같은 코드가에서 잘 작동에는 회원이 없습니다

스위프트 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