2015-10-29 16 views

cevap

40

PlaceHolder TextFiled Swift 3.0

# 1. set tutucu textfield renk Programlı

var myMutableStringTitle = NSMutableAttributedString() 
    let Name = "Enter Title" // PlaceHolderText 

    myMutableStringTitle = NSMutableAttributedString(string:Name, attributes: [NSFontAttributeName:UIFont(name: "Georgia", size: 20.0)!]) // Font 
    myMutableStringTitle.addAttribute(NSForegroundColorAttributeName, value: UIColor.redColor(), range:NSRange(location:0,length:Name.characters.count)) // Color 
    txtTitle.attributedPlaceholder = myMutableStringTitle 

VEYA

txtTitle.attributedPlaceholder = NSAttributedString(string:"Enter Title", attributes: [NSForegroundColorAttributeName: yellowColor]) 

Not: NametextField sizin tutucudur.

yer tutucu TextFiled:

enter image description here

------------------------------- - VEYA -------------------------------------

# 2. Çalışma zamanı özniteliği

  1. textfield mülkiyet kimlik denetçisi Enter Title

    enter image description here

  2. tıklayın Seti textfield tutucu metin de yer tutucu textfield rengini ayarlayın.

    enter image description here

  3. Kullanıcı, Süre Özellikleri tanımlayın renk

    Anahtar Yolu niteliklerini ekleyin: _placeholderLabel.textColor

    Tür: Color

    değeri: Your Color or RGB value

    enter image description here

    yer tutucu TextFiled: Eğer değiştirmek istiyorsanız

    enter image description here

+0

2. çözüm benim için en iyisiydi, “IBOutletCollection” daki tüm alanları gruplamak istedim, ancak her UITextfields'ı nasıl tanımlayacağımı bilemedim. yer tutucu dizgileri. Bu şekilde Swift 3 için mükemmel çalışır. –

3

Sen

let textFld = UITextField(); 
textFld.frame = CGRectMake(0,0, 200, 30) 
textFld.center = self.view.center; 
textFld.attributedPlaceholder = NSAttributedString(string:"Test Data for place holder", attributes:[NSForegroundColorAttributeName: UIColor.blueColor(),NSFontAttributeName :UIFont(name: "Arial", size: 10)!]) 
self.view.addSubview(textFld) 
8

Swift 3

için güncellenmiş bu örnek kodla deneyebilirsiniz Swift 3 UITextField tutucu renk, aşağıdaki kod satırlarını kullanın:

let yourTextFieldName = UITextField(frame: CGRect(x: 0, y: 0, width: 180, height: 21)) 
yourTextFieldName.attributedPlaceholder = NSAttributedString(string: "placeholder text", attributes: [NSForegroundColorAttributeName: UIColor.white]) 
İlgili konular