iPhone 文本字段

发布于 2024-07-26 17:35:03 字数 236 浏览 5 评论 0原文

我遇到了一个尚未解决的问题。 希望有人可以提供帮助。 我有一个应用程序,我用它来做简单的计算,一些结果比 UItextField 大。 有谁知道如何将输出限制为 10 个字符,就像计算器使用指数一样。 这是我当前正在使用的代码。

myVar.text = [[NSString alloc]initWithFormat:@"%2.1", myVar]

这只是限制了小数位。 小数点前面的2没有任何作用。

I have run into an issue that I have yet to be able to solve. Hopefully someone can help. I have an app that I am using to do simple calculations, some of the results are larger than the UItextField. Does anyone know how to limit the output to say 10 characters like say a calculator would using exponents. This is the code I am using currently.

myVar.text = [[NSString alloc]initWithFormat:@"%2.1", myVar]

This just limits the decimal place. The 2 in front of the decimal does nothing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

醉城メ夜风 2024-08-02 17:35:03

你可以这样做。 希望这有助于

#define MAX_LENGTH 20

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if (textField.text.length >= MAX_LENGTH && range.length == 0)
    {
        return NO; // return NO to not change text
    }
    else
    {return YES;}
}

参考:设置 UITextField 的最大字符长度

You could do it this way. Hope this helps

#define MAX_LENGTH 20

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if (textField.text.length >= MAX_LENGTH && range.length == 0)
    {
        return NO; // return NO to not change text
    }
    else
    {return YES;}
}

ref: Set the maximum character length of a UITextField

ゝ杯具 2024-08-02 17:35:03

检查此处。 听起来你想要1.2E或_1.2_e。

Check here. Sounds like you want 1.2E or _1.2_e.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文