2015-07-18 3 views
0

Я знаю, для IO7 и более поздних версий, boundingRectWithSize может выполнять работу. Но для того, чтобы соответствовать всем версиям iOS. Я использую sizeThatFits для calculate.Following мой код:Как настроить высоту UILabel, чтобы она соответствовала размеру?

[email protected]"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;

И результат: enter image description here

последние два слова "обеспечивает доверенные" не хватает !!!!! !

Как всегда, когда я добавить какое-то слово

[email protected]"Visit BBC News for up-to-the-minute news, breaking news, video, audio and feature stories. BBC News provides trusted World and"; 

Результат: enter image description here

Мой дизайн раскадровка: enter image description here

enter image description here

Я думаю, что-то не так с разрыв строки .. w курица следующий текст линия не достаточно долго, следующая строка мисс ..

ответ

1

Попробуйте этот код

[email protected]"Visit BBC News for up-to-the-minute news, breaking news, video, audio and feature stories. BBC News provides trusted";   
self.detailLabel.numberOfLines=0;  
self.detailLabel.lineBreakMode=NSLineBreakByWordWrapping; 
[self.detailLabel sizeToFit]; 
Смежные вопросы