- (int)getMsgLen:(NSString *)msg{
int unicode = 0;//is arabic or english (1=arabic 0=english)
NSString *str = @"دجحخهعغفقثصضطكمنتالبيسشظزوةىلارؤءئإلإألأآلآ،؛؟ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيـًٌٍَُِّْ";
for (int i = 0; i<[str length]; i++) {
NSString *strResult = [str substringWithRange:NSMakeRange(i, 1)];
for (int r = 0; r<[msg length] ;r++) {
NSString *msgResult = [msg substringWithRange:NSMakeRange(r, 1)];
if([strResult isEqualToString:msgResult] && strResult)
unicode = 1;
}
}
int msgLenght = 1;
// arabic value
float oneMsgLenth = 70;
float twoMsgLenth = 67;
// english value
if(unicode == 0){
oneMsgLenth = 160;
twoMsgLenth = 134;
}
int numChar = [msg length];
if( numChar > oneMsgLenth){
msgLenght = ceil(numChar / twoMsgLenth);
}
return msgLenght;
}
我有这个代码,这个代码检查是否有任何阿拉伯字符来改变计算消息的数量,这个代码每次你写一个 UITextView 并且它工作成功,但它太慢了,因为每次点击它都会改变值UIL标签。
有什么建议可以帮助我快速完成吗?