2014-12-10 78 views

回答

1

是的,NSAttributedString是一個答案,因爲是NSMutableAttributedString

創建字符串(這裏稱爲aboutTextBody)後,您a)創建樣式作爲NSDictionary對象,b)在要應用該樣式的文本字符串中查找範圍,以及c)設置字符串的屬性爲那個範圍和風格。用於

示例代碼)是:對於b爲整個字符串

NSDictionary *NWStyle = [[NSDictionary alloc] init]; 
NWStyle = @{NSFontAttributeName:[UIFont fontWithName:@"Noteworthy-Bold" size:18.0]}; 

樣本代碼)和c)是:對於b爲子串的串內

[aboutTextBody setAttributes:NWStyle range:NSMakeRange(0, aboutTextBody.length)]; 

示例代碼)是:對於C的字符串內子

NSRange rangeDV = [holdString rangeOfString:@"DELUXE VERSION"]; 

示例代碼)是:

[aboutTextBody setAttributes:NWStyle range:rangeDV]; 

您還可以設置段落樣式相同的方式對無論是整個字符串或者只子:

NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init]; 
paraStyle.alignment = NSTextAlignmentCenter; 
paraStyle.lineBreakMode = NSLineBreakByWordWrapping; 

編輯補充: 添加段落樣式的方式略有不同:

[aboutTextBody addAttribute:NSParagraphStyleAttributeName value:paraStyle range:rangeDV]; 
相關問題