Text Attributes (via NSAttributedString) not applied to UITextFields

Viewed 35

I have some default styles to apply to a couple of UITextFields. I have the default styles on AppModel.swift as follows:

static let memeTextDefaultAttributes: [NSAttributedString.Key: Any] = [
    .foregroundColor: UIColor.white,
    .strokeColor: UIColor.black,
    .font: UIFont(name: "HelveticaNeue-CondensedBlack", size: 32)!,
    .strokeWidth: 2
  ]

Then, on the below function I set the default styles to the corresponding UITextFields, however, when running the app, no styles are actually applied.

/// Sets up the meme's top and bottom text fields' initial configuration
  func setInitialMemeTextConfig() {
    let memeTextFields = [memeTopText!, memeBottomText!]
    
    for (index, memeTextField) in memeTextFields.enumerated() {
      memeTextField.defaultTextAttributes = AppModel.memeTextDefaultAttributes
      memeTextField.textAlignment = AppModel.memeTextAlignment
      
      if index == 0 {
        memeTextField.text = AppModel.topMemeTextFieldDefaultText
        memeTextField.delegate = memeTopTextFieldDelegate
      } else {
        memeTextField.text = AppModel.bottomMemeTextFieldDefaultText
        memeTextField.delegate = memeBottomTextFieldDelegate
      }
    }
  }

I'm relatively new to iOS programming so if this is a silly mistake of me, please excuse me.

0 Answers
Related