iphone - 从 UITextField 中删除点

标签 iphone ios objective-c

我在应用程序上创建,我需要输入价格。客户需要自己设计的键盘,所以我开发了以下键盘。它工作完美。问题是当文本大于 UITextField 时,它会显示点。我在谷歌和 SO 上搜索但没有找到任何东西。
how to avoid dots next to a uitextfield
How to remove dots in UITextfield?和其他答案,但不适用于我的情况。 当我使用默认键盘时,它会根据我输入的数字滚动文本

我的键盘是

enter image description here

当长度大于 TextFied 宽度时显示

enter image description here

我的代码是

     - (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/

相关文章:

iphone - 使用自定义 View Controller 来管理同一 View 层次结构的不同部分

ios - 我们如何在使用 Eureka 单击单元格后执行条件

objective-c - Xcode 没有为 Objective-C 代码正确格式化文档注释

objective-c - 在 OS X 上利用单独应用程序的资源

iphone - 如何在 iOS 上找到 NSNetService 的正确端口?

iphone - 这段通过 AVAssetWriter 和 AVAssetWriterInputs 编写视频+音频的代码不起作用。为什么?

ios - 如何分组 PFObjects ?解析/swift

ios - 在ios sdk中获取当月星期一的所有日期

ios - 在提交应用程序之前重新上传二进制文件

objective-c - 如何编码 NSInitation?