我是新的IOS
&我正在使用IOS 6
。我的代碼中有多個文本字段,其中一個使用數字鍵盤鍵盤,我想將自定義按鈕添加到它。添加自定義按鈕到數字鍵盤的鍵盤ios 6
我使用這個代碼:
UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
doneButton.frame = CGRectMake(0, 163, 106, 53);
doneButton.adjustsImageWhenHighlighted = NO;
[doneButton setImage:[UIImage imageNamed:@"DoneUp.png"] forState:UIControlStateNormal];
[doneButton setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted];
[doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];
// locate keyboard view
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView* keyboard;
for(int i=0; i<[tempWindow.subviews count]; i++) {
keyboard = [tempWindow.subviews objectAtIndex:i];
// keyboard view found; add the custom button to it
if([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == TRUE)
[keyboard addSubview:doneButton];
}
選擇是所謂的,但問題是,[[tempwindow.subviews]count]
爲0
誰能幫助我?
在此先感謝。
我會建議使用[InputAccessoryView(http://stackoverflow.com/a/11211721/593709) –