在Swift 2.0中如何用完成按钮完成数字小键盘? [英] How to do number keypad with done button in Swift 2.0?

查看:190
本文介绍了在Swift 2.0中如何用完成按钮完成数字小键盘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了很多带有完成按钮的数字键盘,但在SWIFT 2.0中找不到正确的答案.

I've tried lots of numeric keyboard with done button, it's not found a correct answer in SWIFT 2.0.

推荐答案

您可以使用工具栏在键盘上方添加完成按钮

You can add done button above keyboard using toolbar

override func viewDidLoad() {
    super.viewDidLoad()
    let tooBar: UIToolbar = UIToolbar()
    tooBar.barStyle = UIBarStyle.BlackTranslucent
    tooBar.items=[
        UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target: self, action: nil),
        UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.Done, target: self, action: "donePressed")]
    tooBar.sizeToFit()
    yourTextFeild.inputAccessoryView = tooBar
}

func donePressed () {
    yourTextFeild.resignFirstResponder()
}

它看起来像这样

这篇关于在Swift 2.0中如何用完成按钮完成数字小键盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆