Set the placeHolder font of a textField

In a @IBDesignable this allows me to set the font of a textView.

How can I do the something similar for a textField?

Thnaks in advance.


This is how I use the code below on a textView.

balanceDueTextView_Outlet.placeholderFont = UIFont(name: Theme.current.readingFont, size: fontSize)?.italic()


These are in a IBDesignable

override open var font: UIFont! {
    didSet {
        if placeholderFont == nil {
            placeholderLabel.font = font
        }
    }
}
   
open var placeholderFont: UIFont? {
    didSet {
        let font = (placeholderFont != nil) ? placeholderFont : self.font
        placeholderLabel.font = font
    }
}


This is the extension I'm using.

extension UIFont
{
    func withTraits(_ traits:UIFontDescriptor.SymbolicTraits...) -> UIFont
    {
        let descriptor = self.fontDescriptor
            .withSymbolicTraits(UIFontDescriptor.SymbolicTraits(traits).union(self.fontDescriptor.symbolicTraits))
        return UIFont(descriptor: descriptor!, size: 0)
    }
   
    func withoutTraits(_ traits:UIFontDescriptor.SymbolicTraits...) -> UIFont
    {
        let descriptor = self.fontDescriptor
            .withSymbolicTraits(  self.fontDescriptor.symbolicTraits.subtracting(UIFontDescriptor.SymbolicTraits(traits)))
        return UIFont(descriptor: descriptor!, size: 0)
    }
   
    func bold() -> UIFont
    {
        return withTraits(.traitBold)
    }

    func italic() -> UIFont
    {
        return withTraits(.traitItalic)
    }

    func noItalic() -> UIFont
    {
        return withoutTraits(.traitItalic)
    }
   
    func noBold() -> UIFont
    {
        return withoutTraits(.traitBold)
    }
}

In which class is this ?

override open var font: UIFont!


Is it in a subclass of TextView ?


Where is placeholderLabel defined ?


TextField have a attributedPlaceholder property.

You can set it with the attributes you want.

Thanks, I'll try using the attributedPlaceholder.

Set the placeHolder font of a textField
 
 
Q