最佳答案
我想这就是你想要的:
代码:
override func viewDidAppear(_ animated: Bool) {
let viewAcc = UIView()
viewAcc.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: 50)
viewAcc.backgroundColor = UIColor.gray
let newTF = UITextField(frame: CGRect(x: 2, y: 10, width: self.view.frame.size.width - 75 , height: 30))
newTF.backgroundColor = UIColor.white
newTF.borderStyle = UITextBorderStyle.none
let btnDone = UIButton(frame: CGRect(x: newTF.frame.size.width + 10, y: 5, width: 45, height: 30 ))
btnDone.backgroundColor = UIColor.blue
btnDone.setTitle("Done", for: .normal)
viewAcc.addSubview(newTF)
viewAcc.addSubview(btnDone)
self.mytextField.inputAccessoryView = viewAcc
}
引用:
关于ios - 如何在 iOS 中的键盘布局顶部添加预览文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44104816/