0
我试图改变搜索占位符“搜索设备”在表视图更改搜索占位符:通过使用此代码在viewDidLoad中的代码
let placeholderAttributes: [String : AnyObject] = [NSForegroundColorAttributeName: UIColor.blue, NSFontAttributeName: UIFont.systemFont(ofSize: UIFont.systemFontSize)]
let attributedPlaceholder: NSAttributedString = NSAttributedString(string: "Search for a Device", attributes: placeholderAttributes)
let textFieldPlaceHolder = searchBar.value(forKey: "searchField") as? UITextField
textFieldPlaceHolder?.attributedPlaceholder = attributedPlaceholder
我敢肯定,一切都在正常代码,但为什么占位符没有改变?!
我觉得你应该把所有的代码放在viewDidAppear而不是viewDidLoad中。 –
你是否在其他地方设置占位符?也许在故事板上呢? –
很难分辨为什么它不能正常工作..你能分享你的代码,我会尽力帮助你。 –