Ако някой има приложението GymBuddy, ще разбере за какво говоря. Изглежда, че използват стандартната клавиатура Number Pad, но са добавили "." бутон в долния ляв ъгъл, както и лента в горната част за превключване към буквени знаци. Някой знае ли как се прави това? Да направя ли нов изглед като клавиатурата и да го издърпам нагоре и бутоните да съответстват на textField за въвеждане? Изглежда не мога да намеря никаква информация за персонализиране на клавиатура или създаване на ваша собствена. Благодаря
Създаване на персонализиран UIKeyBoard за iPhone
Отговори (2)
Правил съм това. По принцип добавяте свой собствен бутон като подизглед на 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
}
Надявам се това да е ясно.
-Оскар
person
Oscar Gomez
schedule
16.02.2010
Благодаря ви много, ще пробвам това, когато се прибера
- person Chris Sheldrick; 16.02.2010
Вижте тази публикация, това може да е вашият отговор:
UIKeyboardTypeNumberPad и липсващият клавиш "return"
person
Tuyen Nguyen
schedule
27.04.2011