UIKeyBoard 返回按钮 UIReturnKeyDone

发布于 2024-08-25 15:46:08 字数 157 浏览 5 评论 0原文

textfield.returnKeyTYpe = UIReturnKeyDone

因此,上面的内容使键盘上的“返回”按钮显示“完成”。我在 UIKeyBoard 上看到过带有蓝色按钮的应用程序。这足够简单吗?如何更改 Return 键的背景颜色?

textfield.returnKeyTYpe = UIReturnKeyDone

So the above makes my Return button on the keyboard to say Done. I have seen Apps with Blue color button on the UIKeyBoard. Is that simple enough to do? How do I change the background color of the Return key?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

醉生梦死 2024-09-01 15:46:08

仅当 Return 键的类型不是 UIReturnKeyDefault 并且启用时,它才会变成蓝色。要确保它已启用,您可以设置 textfield.enablesReturnKeyAutomatically = YES

The Return key only turns blue if it has a type other than UIReturnKeyDefault and is enabled. To make sure it gets enabled, you can set textfield.enablesReturnKeyAutomatically = YES.

乙白 2024-09-01 15:46:08
textfield.returnKeyType = UIReturnKeyGo;
textfield.returnKeyType = UIReturnKeyGo;
爱*していゐ 2024-09-01 15:46:08

我不完全确定你可以,如果可以,我认为你可能需要滚动自己的键盘或使用未记录的方法。或者,您可以在按钮上绘制自己的视图,并使其对用户触摸透明。 这篇文章可能会对您有所帮助。

I'm not entirely certain you can, and if you can I think that you might need to either roll your own keyboard or use undocumented methods. Alternatively, you could draw your own view over the button and simply make it transparent to user touches. This article might help you.

淡紫姑娘! 2024-09-01 15:46:08

一旦用户在 UITextField 中输入代码,返回键背景颜色就会自动变为蓝色。

The return key background color turns AUTOMATICALLY into blue as soon as the user enters code for e.g. into a UITextField.

十年不长 2024-09-01 15:46:08

以下是执行此操作的 Swift 代码:

extension ViewController {

func subviewsOfView(view : UIView, withType type:NSString) -> NSArray {
    let prefix = NSString(format: "<%@",type) as String
    let subViewsArray = NSMutableArray()
    for subview in view.subviews {
        let tempArray = subviewsOfView(subview, withType: type)
        for view in tempArray {
            subViewsArray.addObject(view)
        }
    }
    if view.description.hasPrefix(prefix) {
        subViewsArray.addObject(view)
    }
    return NSArray(array: subViewsArray)
}

func addColorToUIKeyboardButton() {
    for keyboardWindow in UIApplication.sharedApplication().windows {
        for keyboard in keyboardWindow.subviews {
            for view in self.subviewsOfView(keyboard, withType: "UIKBKeyplaneView") {
                let newView = UIView(frame: (self.subviewsOfView(keyboard, withType: "UIKBKeyView").lastObject as! UIView).frame)
                newView.frame = CGRectMake(newView.frame.origin.x + 2, newView.frame.origin.y + 1, newView.frame.size.width - 4, newView.frame.size.height - 3)
                newView.backgroundColor = UIColor.redColor() //Or whatever color you want
                newView.layer.cornerRadius = 4.0
                view.insertSubview(newView, belowSubview: self.subviewsOfView(keyboard, withType: "UIKBKeyView").lastObject as! UIView)
            }
        }
    }
}
}

注意:在调用 addColorToUIKeyboardButton() 之前,请确保键盘可见。

Here's the code in Swift that does the job:

extension ViewController {

func subviewsOfView(view : UIView, withType type:NSString) -> NSArray {
    let prefix = NSString(format: "<%@",type) as String
    let subViewsArray = NSMutableArray()
    for subview in view.subviews {
        let tempArray = subviewsOfView(subview, withType: type)
        for view in tempArray {
            subViewsArray.addObject(view)
        }
    }
    if view.description.hasPrefix(prefix) {
        subViewsArray.addObject(view)
    }
    return NSArray(array: subViewsArray)
}

func addColorToUIKeyboardButton() {
    for keyboardWindow in UIApplication.sharedApplication().windows {
        for keyboard in keyboardWindow.subviews {
            for view in self.subviewsOfView(keyboard, withType: "UIKBKeyplaneView") {
                let newView = UIView(frame: (self.subviewsOfView(keyboard, withType: "UIKBKeyView").lastObject as! UIView).frame)
                newView.frame = CGRectMake(newView.frame.origin.x + 2, newView.frame.origin.y + 1, newView.frame.size.width - 4, newView.frame.size.height - 3)
                newView.backgroundColor = UIColor.redColor() //Or whatever color you want
                newView.layer.cornerRadius = 4.0
                view.insertSubview(newView, belowSubview: self.subviewsOfView(keyboard, withType: "UIKBKeyView").lastObject as! UIView)
            }
        }
    }
}
}

Note: Make sure the keyboard is visible before you call addColorToUIKeyboardButton()

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文