Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c StringByTrimmingCharactersSet:正在删除过多的字符_Objective C_Nsstring_Uilabel - Fatal编程技术网

Objective c StringByTrimmingCharactersSet:正在删除过多的字符

Objective c StringByTrimmingCharactersSet:正在删除过多的字符,objective-c,nsstring,uilabel,Objective C,Nsstring,Uilabel,我有一个字符串,它表示从rss提要获得的文章的标题。字符串的末尾有空格,所以我需要修剪字符串 cell.title.text = [untrimmedTitle stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; 但是,新字符串不会显示整个标题。例如,“最近一次酒吧之夜的堕胎主题”是“最近一次” 标题存储在通常是多行的UILabel中,我注意到标题总是在从第二行到最后一行的末尾被截断。我在Inter

我有一个字符串,它表示从rss提要获得的文章的标题。字符串的末尾有空格,所以我需要修剪字符串

cell.title.text = [untrimmedTitle stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
但是,新字符串不会显示整个标题。例如,“最近一次酒吧之夜的堕胎主题”是“最近一次”

标题存储在通常是多行的UILabel中,我注意到标题总是在从第二行到最后一行的末尾被截断。我在Interface Builder中将最大行数设置为“0”,并将换行设置为换行

编辑:

下面是代码的较大部分

  NSString *untrimmedTitle = [[stories objectAtIndex: storyIndex] objectForKey: @"title"];
cell.title.text = [untrimmedTitle stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
CGSize maximumLabelSize = CGSizeMake(296,9999);
CGSize expectedLabelSize = [cell.title.text sizeWithFont:cell.title.font constrainedToSize:maximumLabelSize];

//adjust the label to the the new height.
CGRect newFrame = cell.title.frame;
newFrame.size.height = expectedLabelSize.height;
cell.title.frame = newFrame;

您应该
NSLog
修剪的
结果。这是怎么产生的?如果正确,则只有
UILabel
的问题。NSLog显示正确的标题。我正在根据文本大小自动调整UILabel的高度,我想知道这是否是错误的根源。我在上面添加了代码,没关系,我找到了答案。
maximumLabelSize
宽度高于interface builder中标签的宽度,因此无法正确进行自动调整