我知道IO7及更高版本,boundingRectWithSize
可以完成这项工作。但为了适应所有的iOS版本。我使用sizeThatFits来计算。以下是我的代码:
self.detailLabel.text=@"Visit BBC News for up-to-the-minute news, breaking news, video, audio and feature stories. BBC News provides trusted";
self.detailLabel.lineBreakMode = NSLineBreakByWordWrapping;
CGSize size =[self.detailLabel sizeThatFits:CGSizeMake(287, MAXFLOAT)]; //287 is the label's width I set in storyboard
[self.detailLabel setFrame:CGRectMake(self.detailLabel.frame.origin.x, self.detailLabel.frame.origin.y, self.detailLabel.frame.size.width, size.height)];
self.detailLabel.layer.borderColor=[[UIColor blackColor] CGColor];
self.detailLabel.layer.borderWidth=1;
结果是:
最后两个单词“提供信任”缺失!!!!!!
我何时附加一些字
self.detailLabel.text=@"Visit BBC News for up-to-the-minute news, breaking news, video, audio and feature stories. BBC News provides trusted World and";
结果是:
我的故事板设计是:
我觉得换行有问题..当下一行文字不够长时,下一行就错过..
答案 0 :(得分:1)
试用此代码
posts/show