通过代码更改搜索占位符(Change the search placeholder by code)
我正在尝试通过在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
我确信代码中的一切都可以,但为什么占位符没有改变?!
I'm trying to change the search placeholder to "Search for a device" in table view by using this code in 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
I'm sure everything is OK in the code, but why the placeholder is not changing?!
原文:https://stackoverflow.com/questions/39814482
更新时间:2022-05-10 09:05