2017-12-26 5 views
0

textField@IBInspectable 속성 인 placeHolderColor: UIColor을 가지고 있으며 정상적으로 작동합니다. 내 텍스트 필드에 일반 텍스트에 대해이 속성에 대한 프로그래밍 방식으로 불투명도 값 만이 아니라 설정하는 방법UITextField attributed 신속한 보유자 색상 및 불투명도 4

attributedPlaceholder = NSAttributedString(string: placeHolder, attributes:[NSAttributedStringKey.foregroundColor: placeHolderColor]) 

: 나는하여 설정? 이 작업을 수행하기 위해 NSAttributedStringKey을 찾지 못했습니다

답변

0

UIColor 등급 방법 withAlphaComponent(alpha:) 색상을 설정하려면 alpha를 설정하십시오. read more

@IBInspectable var placeholderTextColor: UIColor? { 
    set { 
     guard let color = newValue else { return } 

     let placeholderText = self.placeholder ?? "" 
     attributedPlaceholder = NSAttributedString(string: placeholderText, attributes: [NSAttributedStringKey.foregroundColor: color.withAlphaComponent(alpha: self.alpha)]) 
    } 
    get{ 
     return self.placeholderTextColor 
    } 
}