2010-03-19 92 views
2
textfield.returnKeyTYpe = UIReturnKeyDone 

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

+0

的任何实例之前键盘是可见的? __ – kennytm 2010-03-20 06:22:03

回答

1

我不完全确定你可以,如果你能我认为你可能需要滚动自己的键盘或使用无证方法。或者,您可以在按钮上绘制自己的视图,并简单地对用户触摸进行透明处理。 This article可能会帮助你。

4

如果回车键的类型不是UIReturnKeyDefault已启用,回车键才会变为蓝色。为确保启用,您可以设置textfield.enablesReturnKeyAutomatically = YES

+1

好吧,我试过,没有工作。我看到的蓝色按钮是在iPhone应用程序上。 iPad有什么不同?我正在使用SDK 3.2 Beta 5. – Dave 2010-03-20 17:25:19

+1

我不确定iPad是否以相同方式突出显示Return键。 – Tom 2010-03-20 20:25:50

2
textfield.returnKeyType = UIReturnKeyGo; 
0

只要用户输入例如用于输入的代码,返回键背景颜色就会自动变成蓝色。成为UITextField

+0

不,它不。 。 – Rambatino 2014-06-19 17:21:56

0

下面是斯威夫特,没有工作的代码:

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()