2015-10-29 5 views
8

स्विफ्ट 2.0 में UITextfieldplaceholder & fontsize कैसे बदलें?स्विफ्ट 2.0 का उपयोग कर UITextfield प्लेसहोल्डर रंग और फोंटनाइज़ को कैसे बदलें?

+0

http://stackoverflow.com/a/26076202/988169 – pkc456

+2

(http [स्विफ्ट के साथ बदल रहा है प्लेसहोल्डर पाठ का रंग] के संभावित डुप्लिकेट: // stackoverflow.com/questions/26076054/changing-placeholder-text-color-with-swift) – Moritz

उत्तर

40

PlaceHolder TextFiled Swift 3.0

# 1। सेट प्लेसहोल्डर पाठ फ़ील्ड रंग प्रोग्राम

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 

या

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

नोट: NametextField के अपने प्लेसहोल्डर है।

प्लेसहोल्डर TextFiled:

enter image description here

------------------------------- - या -------------------------------------

# 2। क्रम विशेषता

  1. सेट पाठ फ़ील्ड प्लेसहोल्डर पाठ Enter Title

    enter image description here

  2. पाठ फ़ील्ड संपत्ति की पहचान निरीक्षक पर क्लिक करें पर प्लेसहोल्डर पाठ फ़ील्ड रंग निर्धारित किया है।

    enter image description here

  3. उपयोगकर्ता परिभाषित क्रम गुण, रंग विशेषताओं

    कुंजी पथ जोड़ें: _placeholderLabel.textColor

    प्रकार: Color

    मूल्य: Your Color or RGB value

    enter image description here

    प्लेसहोल्डर TextFiled:

    enter image description here

+0

दूसरा समाधान मेरे लिए सबसे अच्छा था, मैं 'IBOutletCollection' में सभी फ़ील्ड को समूहबद्ध करना चाहता था, हालांकि मुझे यह सुनिश्चित नहीं था कि प्रत्येक UITextfields को कैसे परिभाषित किया जाए प्लेसहोल्डर तार। इस तरह स्विफ्ट 3 के लिए बिल्कुल सही काम करता है। –

3

आप बदलना चाहते हैं यह नमूना कोड

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

स्विफ्ट 3

के लिए अपडेट किया गया साथ कोशिश कर सकते हैं स्विफ्ट 3 के लिए UITextField प्लेसहोल्डर रंग, कोड की निम्न लाइनों का उपयोग करें:

let yourTextFieldName = UITextField(frame: CGRect(x: 0, y: 0, width: 180, height: 21)) 
yourTextFieldName.attributedPlaceholder = NSAttributedString(string: "placeholder text", attributes: [NSForegroundColorAttributeName: UIColor.white]) 
संबंधित मुद्दे