Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在自定义键盘上实现自定义字体,以便在其他应用程序上使用?_Ios_Swift_Custom Keyboard - Fatal编程技术网

Ios 如何在自定义键盘上实现自定义字体,以便在其他应用程序上使用?

Ios 如何在自定义键盘上实现自定义字体,以便在其他应用程序上使用?,ios,swift,custom-keyboard,Ios,Swift,Custom Keyboard,我正在用Swift 5.0编码。我想创建一个应用程序,用户可以下载自定义字体并在任何应用程序中使用它们。我正在使用键盘扩展来实现这一点 这是我的密码 class KeyboardViewController: UIInputViewController { override func viewDidLoad() { super.viewDidLoad() let button = createButton(title: "A") self.view.addSubview

我正在用Swift 5.0编码。我想创建一个应用程序,用户可以下载自定义字体并在任何应用程序中使用它们。我正在使用键盘扩展来实现这一点

这是我的密码

class KeyboardViewController: UIInputViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    let button = createButton(title: "A")
    self.view.addSubview(button)
}

func createButton(title: String) -> UIButton {
    let button = UIButton(type: .system)
    button.frame = CGRect(x: 0,y: 0,width: 20,height: 20)
    button.setTitle(title, for: .normal)
    button.sizeToFit()
    button.translatesAutoresizingMaskIntoConstraints = false
    button.titleLabel?.font = UIFont(name: "Montague.ttf", size: 15)
    button.backgroundColor = UIColor(white: 1.0, alpha: 1.0)
    button.setTitleColor(UIColor.darkGray, for: .normal)
    button.addTarget(self, action: #selector(didTapButton(sender:)), for: .touchUpInside)

    return button
}

@objc func didTapButton(sender: AnyObject) {
     let button = sender as! UIButton
     button.titleLabel?.font = UIFont(name: "Montague.ttf", size: 15)
     let title = button.title(for: .normal)
     textDocumentProxy.insertText(title!)
}
这是输出


因此,我的问题是如何使键盘按钮以我想要的字体显示和输出?

您可以使用按钮的标题标签属性自定义按钮的标题字体

button.titleLabel?.font = UIFont(name: "YourCustomFont", size: 10.0)
当应用程序开发人员决定在他们的应用程序AFAIK中使用什么字体时,您不能更改输出上的字体

编辑:我不知道你设置输出是什么意思,有关你链接到的应用程序的更多信息,请阅读以下帖子:


tl;dr:你不能设置自定义字体,那些应用程序使用Unicode,如果你选择,你也应该这样做。

如你所见,我就是这么做的。但是,我希望输出为自定义字体。应用商店中有很多应用都具有此功能。e、 g.,嘿,你们能告诉我如何获得键盘的高度吗,UIResponder的通知。keyboardWillShowNotification在键盘分机中不起作用。还有别的办法吗?