ios - 如何在 iOS 中的键盘布局顶部添加预览文本

标签 ios swift keyboard-events

我想在键盘顶部显示预览文本,如下所示:

如何解决这个问题?

最佳答案

我想这就是你想要的:

enter image description here

代码:

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
    }

引用:

Apple Doc Reference

关于ios - 如何在 iOS 中的键盘布局顶部添加预览文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44104816/

相关文章:

iOS Facebook 权限

ios - 我需要实现导航 Controller 来制作 UISearchViewController 吗?

ios - 将选择器从 UIViewController 传递到 UIView

ios - Swift 中奇怪的保留周期

c++ - 按下键盘时 SFML Sprite 不移动

swift - 在 Swift 中获取键盘代码的键名

c# - 如何在 C# 中捕获删除按键?

iphone - 在 iOS 应用程序中通过 WhatsApp 共享图像/文本

ios - remoteControlReceived(带有事件 : UIEvent?)未触发

ios - 弹出 View Controller 未显示