串/的.text的设置最大长度(Setting Max length of string/.text

2019-09-16 13:42发布

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

-(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个字母最多是否有任何人谁可以告诉我如何做到这一点?

谢谢

Answer 1:

添加此行 -

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

......或者采用同样的你要截断任何字符串。

看看苹果的文档进行一些真正有用的东西NSString的



文章来源: Setting Max length of string/.text
标签: ios xcode string