【发布时间】:2014-12-19 23:40:02
【问题描述】:
我很难弄清楚如何为 iOS 8 创建自定义键盘扩展。我可以很好地完成功能并且调整颜色真的不是问题,布局 然而是主要问题。 我尝试了很多疯狂的方法来找出最好的布局,例如检查输入视图的宽度或容器应用程序视图的宽度(显然都不允许),然后确定它是什么设备我可以根据设备的屏幕尺寸和方向来计算按键的大小、高度和位置的比率。
到目前为止,该应用程序仅使用代码和 0 个 nib 文件或故事板进行键盘布局。如果有人可以帮助我,那就太棒了!
现在每个键都有一个功能,例如 q 键
//Q Key
func addQKey()
{
var qKey = UIButton.buttonWithType(.System) as UIButton
qKey.setTitle(NSLocalizedString("Q", comment: "Q Key"), forState: .Normal)
qKey.sizeToFit()
qKey.frame = CGRect(x: 5, y: 14, width: (view.bounds.size.width / 6), height: 20)
qKey.titleLabel?.font = UIFont(name: "Avenir-Black", size: 20)
//qKey.backgroundColor = UIColor(red: 255, green: 0, blue: 0, alpha: 0)
//qKey.backgroundColor = UIColor(white: 1, alpha: 1)
qKey.setTitleColor(UIColor.whiteColor(), forState: .Normal)
qKey.addTarget(self, action: "didTapButton:", forControlEvents: .TouchUpInside)
self.view.addSubview(qKey)
}
这插入一个方法,然后插入文本
//TapButton Began
func didTapButton(sender : AnyObject)
{
let button = sender as UIButton
let title = button.titleForState(.Normal)
var proxy = textDocumentProxy as UITextDocumentProxy
proxy.insertText(title!)
}
如果您有更好的方法或知道如何解决问题,请告诉我!源代码也能救我一命!
【问题讨论】:
-
你能printscreen怎么看键盘吗?
标签: iphone swift layout keyboard