从UITextField删除点 [英] Remove dot from UITextField

查看:51
本文介绍了从UITextField删除点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序上创建,我需要输入价格.客户需要自己设计的键盘,因此我开发了以下键盘.它完美地工作.问题是当文本大于 UITextField 的文本时,它会显示点.我在Google和SO上搜索,但未找到任何东西.
如何避免uitextfield旁边的点
如何删除UITextfield中的点?和其他答案,但在我的情况下不起作用.当我使用默认键盘时,它会滚动我输入数字的文本

I create on application and i required to enter price. client required its own design keyboard so i develop following keyboard. it works perfect . Problem is when the text is larger then UITextField's with then it display dots. I search on google and SO but not found any thing.
how to avoid dots next to a uitextfield
How to remove dots in UITextfield? and other answer but not working in my case. When I used default keyboard it scroll the text what i input number

我的键盘是

如果长度大于TextFied Width,则显示

when length is greater then TextFied Width then it display

我的代码是

     - (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;
   }

推荐答案

您可以尝试以下方法:

self.txtPrice.font = [UIFont systemFontOfSize: 14.0];
self.txtPrice.adjustsFontSizeToFitWidth = YES;
self.txtPrice.minimumFontSize = 7.0;

"adjustsFontSizeToFitWidth"是一个布尔值,指示是否应减小字体大小以使文本字符串适合文本字段的边界矩形.

"adjustsFontSizeToFitWidth" is a Boolean value indicating whether the font size should be reduced in order to fit the text string into the text field’s bounding rectangle.

"minimumFontSize"是用于绘制文本字段文本的最小允许字体的大小.

"minimumFontSize" is the size of the smallest permissible font with which to draw the text field’s text.

这篇关于从UITextField删除点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆