2014-01-13 42 views

回答

7

要獲得RTLabel的高度用 「optimumSize」 屬性。

RTLabel *someLabel = [[RTLabel alloc] init]; 
someLabel.frame = CGRectMake(0.f, 0.f, 300.f,100.f); 
someLabel.text = @"<p>Some <b>HTML</b></p>"; 
CGSize optimumSize = [someLabel optimumSize]; 
someLabel.frame = CGRectMake(0.f, 0.f, 300.f,optimumSize.height); 
0

我認爲這只是

CGFloat height = CGRectGetHeight(rtLabel.bounds) 
+1

更好的位將使用讀出來'CGRectGetHeight()','即高度CGFloat的= CGRectGetHeight(rtLabel.bounds);'此外,蘋果建議不要用命名實例變量[前導下劃線]( http://stackoverflow.com/questions/3521254/prefixing-property-names-with-an-underscore-in-objective-c),只是要記住。 –

+0

更新,我剛剛從Github -https://github.com/honcheng/RTLabel使用RTLabel項目,但將其更改爲rtLabel。 – ansible