UIColor
withAlphaComponent(alpha: )
设置颜色 alpha 的类方法。阅读更多
@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
}
}
在斯威夫特 4.2
attributedPlaceholder = NSAttributedString(string: placeholderText, attributes: [NSAttributedString.Key.foregroundColor: color.withAlphaComponent(self.alpha)])