2014-01-31 77 views
0

我試圖將我的標籤大小設置爲動態,但是此當前方法已棄用。我知道,正確的方法是:使用boundingRectWithSize創建動態標籤:options:attributes:context:

boundingRectWithSize:options:attributes:context: 

這確實沒有與斷行模式沿修改字體大小做的伎倆。

CGSize expectedLabelSize; 
expectedLabelSize = [textLabel.text sizeWithFont:[UIFont fontWithName:@"Ubuntu-Bold" size:14] constrainedToSize:maximumLabelSize 
             lineBreakMode:NSLineBreakByWordWrapping]; 

是否有應該用來改變我的標籤屬性的另一種方法是什麼?

回答

1

剛剛嘗試這個..

NSDictionary *attributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName,nil]; 
CGSize labelContraints    = CGSizeMake(width, 105.0);//Here I set maximum height as 105 for maximum of 5 lines. 
NSStringDrawingContext *context  = [[NSStringDrawingContext alloc] init]; 
CGRect labelRect     = [str boundingRectWithSize:labelContraints 
    options:NSStringDrawingUsesLineFragmentOrigin attributes:attributesDictionary 
context:context]; 

注:將工作IOS7+