2012-02-08 73 views
3

我試圖在文本的一部分上加上「粗體」,但我無法做到。加粗文本時出錯 - Objective-C

我使用這個:

NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"this is a part of the text"]; 
    NSRange selectedRange = NSMakeRange(5, 10); 

    [string beginEditing]; 

    [string addAttribute:NSFontAttributeName 
      value:[NSFont fontWithName:@"Helvetica-Bold" size:12.0] 
      range:selectedRange]; 
    [string endEditing]; 

我得到一個錯誤 「使用未聲明的標識符NSFontAttributeName」;

我該怎麼辦?

+0

看來你錯過了一個擴展名:谷歌的「NSAttributedString Application Kit」。 – Polynomial 2012-02-08 09:43:45

回答

2

NSFontAttributeName是Mac上AppKit中定義的常量,它在iOS上不存在。事實上,UIKit不提供樣式和繪製NSAttributedString實例的附加內容。我發現有一篇博客文章顯示how to use the underlying Core Text attributes

+0

從iOS 6開始,這不再是真實的 – Warpling 2015-01-30 20:40:01