Declare UITextField and setup fields. Set decorated NSAttributedString for UITextField.attributedPlaceholder to set custom color or font etc.
let textField : UITextField = {
$0. returnKeyType = . done
$0. attributedPlaceholder = NSAttributedString (
string: " 이메일을 입력하세요 " ,
attributes: [ NSAttributedString . Key. foregroundColor: UIColor . systemRed. withAlphaComponent ( 0.7 ) ]
)
$0. textAlignment = . left
$0. font = UIFont . systemFont ( ofSize: 30 , weight: . bold)
$0. tintColor = UIColor . systemGreen
$0. setContentHuggingPriority ( . required, for: . horizontal)
return $0
} ( UITextField ( ) )
Drop shadow for only text use NSShadow()
textField. addTarget ( self , action: #selector( didChangeText ( _: ) ) , for: . editingChanged)
@objc
func didChangeText( _ textField: UITextField ) {
guard let text = textField. text else { return }
textField. attributedText = shadowedAttributedText ( from: text)
}
func shadowedAttributedText( from string: String ) -> NSAttributedString {
NSAttributedString ( string: string, attributes: [
NSAttributedString . Key. font: UIFont . systemFont ( ofSize: 30 , weight: . bold) ,
NSAttributedString . Key. foregroundColor: UIColor . green,
NSAttributedString . Key. shadow: {
$0. shadowColor = UIColor . black. withAlphaComponent ( 0.5 )
$0. shadowOffset = CGSize . zero
$0. shadowBlurRadius = 4
return $0
} ( NSShadow ( ) )
] )
}