我在应用程序上创建,我需要输入价格。客户需要自己设计的键盘,所以我开发了以下键盘。它工作完美。问题是当文本大于 UITextField
时,它会显示点。我在谷歌和 SO 上搜索但没有找到任何东西。
how to avoid dots next to a uitextfield
How to remove dots in UITextfield?和其他答案,但不适用于我的情况。 当我使用默认键盘时,它会根据我输入的数字滚动文本
我的键盘是
当长度大于 TextFied 宽度时显示
我的代码是
- (IBAction)numberPressed:(id)sender {
UIButton *btn=(UIButton *)sender;
int number=btn.tag;
if (number <= 9)
txtPrice.text = [NSString stringWithFormat:@"%@%d",txtPrice.text, number];
//decimal point
else if (number == 10) {
if ([txtPrice.text rangeOfString:@"."].location == NSNotFound)
txtPrice.text = [NSString stringWithFormat:@"%@.", txtPrice.text];
}
//0
else if (number == 11)
txtPrice.text = [NSString stringWithFormat:@"%@0", txtPrice.text];
//backspace
else if (number == 12) {
if ([txtPrice.text length] > 0)
txtPrice.text = [txtPrice.text substringToIndex:[txtPrice.text length] - 1];
else
txtPrice.text = @"";
}
}
#pragma mark -
#pragma mark -TextField Delegate Method
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
[self showKeyboard];
return NO; // Hide both keyboard and blinking cursor.
}
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
return YES;
}
最佳答案
UITextField
特别是一行。因此,无论 UITextField
多大,当它到达末尾时都会显示点。
您需要使用 UITextView
而不是 UITextField
来显示和编辑多行
文本。
在 Interface Builder 中,将 UITextView
添加到您想要的位置,然后选择“可编辑”框。默认情况下,它将是多行
。
我想这对你有帮助。 ^_^
关于iphone - 从 UITextField 中删除点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16911628/