2
textfield.returnKeyTYpe = UIReturnKeyDone

所以上面让我在键盘上的返回按钮说完成。我在 UIKeyBoard 上看到了带有蓝色按钮的应用程序。这足够简单吗?如何更改 Return 键的背景颜色?

4

5 回答 5

4

Return 键只有在它的类型不是UIReturnKeyDefault 并且启用时才会变为蓝色。为了确保它被启用,您可以设置textfield.enablesReturnKeyAutomatically = YES.

于 2010-03-20T00:29:12.863 回答
2
textfield.returnKeyType = UIReturnKeyGo;
于 2010-07-16T13:13:04.067 回答
1

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

于 2010-03-19T22:00:19.900 回答
0

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

于 2012-02-29T11:50:47.917 回答
0

这是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()之前键盘是可见的

于 2016-03-19T03:03:53.030 回答