NSAttributedStringKey giving an unresolved identifier error

后端 未结 6 1785
暖寄归人
暖寄归人 2020-12-30 04:15

I\'m following an online tutorial to build a magazine type iOS application. I\'m attempting to use NSAttributedStringKey but keep getting the error shown below. Any ideas?

6条回答
  •  时光取名叫无心
    2020-12-30 04:43

    This example works only iOS11.

    import UIKit
    
    class VC: UIViewController { 
    
        @IBOutlet weak var usernameTxt: UITextField!
        @IBOutlet weak var emailTxt: UITextField!
        @IBOutlet weak var passTxt: UITextField!
    
        override func viewDidLoad() {
            super.viewDidLoad()
            setupView()
        }
    
        func setupView() {
            usernameTxt.attributedPlaceholder = NSAttributedString(string: "username", attributes: [NSAttributedStringKey.foregroundColor: smackPurplePlaceholder])
            emailTxt.attributedPlaceholder = NSAttributedString(string: "email", attributes: [NSAttributedStringKey.foregroundColor: smackPurplePlaceholder])
            passTxt.attributedPlaceholder = NSAttributedString(string: "password", attributes: [NSAttributedStringKey.foregroundColor: smackPurplePlaceholder])  
        }    
    }
    

提交回复
热议问题