我有一个字符串,它代表从 rss 提要获得的文章的标题。字符串末尾有空格,所以我需要修剪字符串。
cell.title.text = [untrimmedTitle stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
但是,新字符串不会显示整个标题。例如,“最新酒吧之夜的堕胎主题”剪辑为“最新”。
标题存储在通常是多行的 UILabel 中,我注意到标题总是在倒数第二行的末尾被截断。我在 Interface Builder 中将最大行数设置为“0”,并将换行符设置为 Word Wrap。
编辑:
这是代码的较大部分。
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;