gpt4 book ai didi

ios - 设置字符串/.text 的最大长度

转载 作者:行者123 更新时间:2023-11-29 11:14:11 25 4
gpt4 key购买 nike

我现在使用按钮在栏中显示字母,这是我使用的代码

-(IBAction) clicked: (id)sender{
NSString *titleOfButton = [sender titleForState:UIControlStateNormal];
NSString *newLabelText = titleOfButton;
labelsText.text = [NSString stringWithFormat:@"%@%@", labelsText.text, newLabelText];

//if ([newLabelText length] >= 5) newLabelText = [newLabelText substringToIndex:5];
}

我遇到的问题是我希望它最多能够输入 5 个字母,有谁能告诉我该怎么做吗?

谢谢

最佳答案

添加这一行 -

if ([newLabelText length] >= 5) newLabelText = [newLabelText substringToIndex:5];

...或将相同的方法应用于您要截断的任何字符串。

查看 Apple 文档以获得一些非常有用的 NSString 内容

关于ios - 设置字符串/.text 的最大长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10165257/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com