Вот код в 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 ()