2012-03-19 62 views
0

嗨我需要使用CTFontRef幾個字體的iPad應用程序,我需要使用此方法,因爲我的字體不是英文。所以我發現這個代碼從這個site問題與CTFontRef

但編譯器給了我一些錯誤:

CTFontRef font = CTFontCreateWithName(CFSTR("myfont"), 12,NULL); 

NSMutableAttributedStringRef attrString = [[NSMutableAttributedString alloc] initWithString:textView.text]; 
[attrString addAttribute:(NSString*)kCTFontAttributeName 
        value:(id)font 
        range: NSMakeRange(0, textView.text.length)]; 

enter image description here

,如果你幫我解決問題

回答

0

代碼存在問題與NSMutableAttributedStringRef。改爲使用NSMutableAttributedString

NSString *myString = @"Hello World!!"; 
CTFontRef futura = CTFontCreateWithName(CFSTR("Futura"), 24.0, NULL); 

NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] 
     initWithString:myString]; 

[attString addAttribute:(NSString *)kCTFontAttributeName 
        value:(id)futura 
        range:NSMakeRange(0, 4)]; 
1

只看到這一點,我將不勝感激。可能對您有用:

CTFontRef font = CTFontCreateWithName(CFSTR("GujaratiSangamMN-Bold"),12.0f, NULL); 
NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys: 
         (id)font, kCTFontAttributeName, 
         nil]; 
NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:textView.text 
                   attributes:attrs]; 
+0

謝謝,我該如何使用attrString?因爲它無法使用,因爲字體沒有改變 – 2012-03-19 09:08:21

+0

好吧最後告訴我你想要什麼? – Hector 2012-03-19 09:10:32

+0

Textview.text的字體應該改變!這就是它 – 2012-03-19 10:22:01