您好,我需要使用一个iPad应用程序与CTFontRef的几个字体,我需要使用这种方法,因为我的字体不是英语。所以我从这个site中找到了这段代码
但是编译器给了我一些错误:
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)];

如果你能帮我解决这个问题,我将不胜感激。
发布于 2012-04-24 20:59:25
代码的问题出在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)];发布于 2012-03-19 17:03:56
看看这个。可能对您有用:
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];https://stackoverflow.com/questions/9767178
复制相似问题