textfield.returnKeyTYpe = UIReturnKeyDone
したがって、上記により、キーボードの Return ボタンが Done と表示されます。UIKeyBoard に青色のボタンが付いたアプリを見たことがあります。それは簡単なことですか?Return キーの背景色を変更するにはどうすればよいですか?
textfield.returnKeyTYpe = UIReturnKeyDone
したがって、上記により、キーボードの Return ボタンが Done と表示されます。UIKeyBoard に青色のボタンが付いたアプリを見たことがあります。それは簡単なことですか?Return キーの背景色を変更するにはどうすればよいですか?
Return キーは、それ以外のタイプがあり、有効になっている場合にのみ青色に変わりUIReturnKeyDefault
ます。確実に有効にするには、 を設定できますtextfield.enablesReturnKeyAutomatically = YES
。
textfield.returnKeyType = UIReturnKeyGo;
できるかどうかは完全にはわかりません。できる場合は、独自のキーボードを転がすか、文書化されていない方法を使用する必要があると思います。または、ボタンの上に独自のビューを描画して、ユーザーのタッチに対して透過的にすることもできます。この記事が役立つかもしれません。
仕事をする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()を呼び出す前に、キーボードが表示されていることを確認してください。
The return key background color turns AUTOMATICALLY into blue as soon as the user enters code for e.g. into a UITextField
.