2010-03-19 34 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()