如果任何人有應用程序GymBuddy,那麼他們會知道我在說什麼。他們似乎使用股票數字鍵盤鍵盤,但添加了「。」。左下角的按鈕以及頂部的橫條切換到字母字符。有誰知道如何做到這一點?我是否可以像鍵盤一樣創建一個新視圖並將其拉出,並使按鈕與輸入的textField相對應?我似乎無法找到有關自定義鍵盤或創建自己的任何信息。謝謝爲iPhone創建自定義UIKeyBoard
0
A
回答
5
我已經這樣做了。基本上你可以像這樣添加你自己的按鈕作爲UIKeyboard的子視圖:
// This function is called each time the keyboard is going to be shown
- (void)keyboardWillShow:(NSNotification *)note {
// Just used to reference windows of our application while we iterate though them
UIWindow* tempWindow;
// Because we cant get access to the UIKeyboard throught the SDK we will just use UIView.
// UIKeyboard is a subclass of UIView anyways
UIView* keyboard;
// Check each window in our application
for(int c = 0; c < [[[UIApplication sharedApplication] windows] count]; C++)
{
// Get a reference of the current window
tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:c];
// Loop through all views in the current window
for(int i = 0; i < [tempWindow.subviews count]; i++)
{
// Get a reference to the current view
keyboard = [tempWindow.subviews objectAtIndex:i];
// From all the apps i have made, they keyboard view description always starts with <UIKeyboard so I did the following
if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
{
// Only add the Decimal Button if the Keyboard showing is a number pad. (Set Manually through a BOOL)
if (numberPadShowing && [keyboard viewWithTag:123] == nil) {
// Set the Button Type.
dot = [UIButton buttonWithType:UIButtonTypeCustom];
// Position the button - I found these numbers align fine (0, 0 = top left of keyboard)
dot.frame = CGRectMake(0, 163, 106, 53);
dot.tag = 123;
// Add images to our button so that it looks just like a native UI Element.
[dot setImage:[UIImage imageNamed:@"dotNormal.png"] forState:UIControlStateNormal];
[dot setImage:[UIImage imageNamed:@"dotHighlighted.png"] forState:UIControlStateHighlighted];
//Add the button to the keyboard
[keyboard addSubview:dot];
// When the decimal button is pressed, we send a message to ourself (the AppDelegate) which will then post a notification that will then append a decimal in the UITextField in the Appropriate View Controller.
[dot addTarget:self action:@selector(sendDecimal:) forControlEvents:UIControlEventTouchUpInside];
return;
}
else if (numberPadShowing && [keyboard viewWithTag:123])
{
[keyboard bringSubviewToFront:dot];
}
else if (!numberPadShowing)
{
for (UIView *v in [keyboard subviews]){
if ([v tag]==123)
[v removeFromSuperview];
}
}
}
}
}
}
- (void)sendDecimal:(id)sender {
// The decimal was pressed
}
希望很清楚。
-Oscar
3
檢查這個帖子,這可能是你的答案:
相關問題
- 1. 自定義UIKeyboard
- 2. Iphone創建自定義UIobject
- 3. 爲iPhone創建自定義滑塊
- 4. 創建iPhone自定義圖片庫
- 5. 帶UIKeyboard +自定義工具欄佈局的iPhone/iOS
- 6. 自定義數字鍵盤UIKeyboard
- 7. iphone UIKeyboard風景
- 8. 如何爲iPhone創建自定義室內地圖的指示?
- 9. 如何爲iPhone創建自定義控件?
- 10. 爲iPhone創建自定義國際鍵盤
- 11. 如何爲iPhone創建自定義界面生成器插件?
- 12. 我可以爲iPhone創建自定義觸摸事件
- 13. 創建自定義綁定
- 14. UIKeyboard與iPhone OS 4
- 15. 爲Visual Studio創建自定義UserControl TestContainer
- 16. 爲ListBox創建自定義文本值
- 17. 爲lightswitch創建自定義組件
- 18. 爲Wordpress創建自定義標籤
- 19. 無法爲自定義MembershipProvider創建MembershipUser
- 20. nagios爲jenkins創建自定義警報
- 21. 爲rails_admin創建自定義字段
- 22. 爲wcf創建自定義對象
- 23. 爲Orchard創建自定義模塊
- 24. 爲Apache2創建fail2ban自定義規則
- 25. 如何爲ListView創建自定義ArrayAdapter
- 26. 創建後自定義對象爲空
- 27. 爲Google Analytics創建自定義指標
- 28. 爲Android創建自定義瀏覽器
- 29. 爲ASP.Net創建一個自定義PrincipalPermission
- 30. 爲setDefaultCloseOperation創建自定義操作?
非常感謝你,當我回家,我會嘗試了這一點 –