2015-11-21 2 views
2

Я использовал следующий код для установки другого шрифта для текста UITextField в (16) и заполнитель (9),Настройка шрифта для UITextField место держателя в быстрой

m_searchTextField.font = UIFont .systemFontOfSize(16) 
let font = UIFont .systemFontOfSize(9) 
let attributes = [ 
     NSForegroundColorAttributeName: UIColor.lightGrayColor(), 
     NSFontAttributeName : font] 

m_searchTextField.attributedPlaceholder = NSAttributedString(string: "Search String be in meddle left", 
     attributes:attributes) 

Размер шрифта установлен правильно, но текстовые наборы заполнителей несколько верхний в текстовом поле.

enter image description here

Как я могу решить эту проблему? Какие-либо предложения?

+0

http://stackoverflow.com/questions/27652227/text-view-placeholder-swift/28271069#28271069 – clearlight

ответ

2

Я исправил эту проблему программно, так как не мог найти другого способа ее исправить.

код ниже:

class ViewController: UIViewController { 

    @IBOutlet weak var textField: UITextField! 
    var placeholder : UILabel! 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     placeholder = UILabel(frame: CGRect(x: 0, y: 0, width: textField.bounds.width, height: textField.bounds.height)) 
     placeholder.text = "Search String be in meddle left" 
     placeholder.font = UIFont.italicSystemFontOfSize(9) 
     placeholder.textColor = UIColor.grayColor() 
     placeholder.hidden = !textField.text!.isEmpty 
     placeholder.textAlignment = .Center 
     textField.addSubview(placeholder) 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
    } 

    @IBAction func textField_EditingChanged(sender: AnyObject) { 
     placeholder.hidden = !textField.text!.isEmpty 
    } 
} 
Смежные вопросы