Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

523
Views
El marcador de posición UITextField y el tamaño del texto deben estar separados - Swift

Mi requisito es que cuando el marcador de posición del campo de texto esté visible, su color debe ser gris y el tamaño de fuente 10, pero cuando el usuario comienza a escribir en el campo de texto, su color debe ser negro y el tamaño de fuente 14. Probé esto:

 textField.attributedPlaceholder = NSAttributedString(string: placeholderText, attributes: [NSAttributedString.Key.foregroundColor: Color.iPhoneGrayColor, NSAttributedString.Key.font: UIFont(name: "SourceSansPro-Regular", size: 10)!]) textField.textColor = UIColor.black textField.font = UIFont(name: "SourceSansPro-Regular", size: 14)!

Pero, el tamaño de fuente de mi marcador de posición está siendo reemplazado por textfield.font , por lo que no puedo obtener un marcador de posición de tamaño 10. ¿Dónde me estoy equivocando? Intenté esto por un par de horas ahora. Cualquier ayuda será apreciada.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Simplemente configure el marcador de posición después de configurar la fuente, ya que la configuración de la fuente también se aplica al marcador de posición (consulte https://developer.apple.com/documentation/uikit/uitextfield/1619604-font ):

 textField.font = ... textField.textColor = ... textField.attributedPlaceholder = ...
over 4 years ago · Santiago Trujillo Report

0

Pruebe este código en su método viewDidLoad() :

 textField.attributedPlaceholder = NSAttributedString(string: placeholderText, attributes: [NSAttributedString.Key.foregroundColor: Color.iPhoneGrayColor, NSAttributedString.Key.font: UIFont(name: "SourceSansPro-Regular", size: 10)!]) textField.textColor = UIColor.black textField.font = UIFont(name: "SourceSansPro-Regular", size: 14)!
over 4 years ago · Santiago Trujillo Report

0

Simplemente pruebe este código, tome la salida de acción UITextFieldEditingChanged y utilícelo como se muestra a continuación.

 @IBAction func nameTextFieldEditingChanged(_ sender: UITextField) { if sender.text?.isEmpty ?? true { //placeholder text size set here textField.font = UIFont(name: "SourceSansPro-Regular", size: 10)! } else { // When user starting typing textField.textColor = UIColor.black textField.font = UIFont(name: "SourceSansPro-Regular", size: 14)! } }

Si tiene alguna duda, por favor comente].

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!