Reputation: 6051
Hi I need using a couple of fonts with CTFontRef
for an iPad application , I need use this method because my font is not English . so I found this code from this site
but compiler gives me some error :
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)];
I would be grateful if you help me to solve the problem
Upvotes: 0
Views: 1830
Reputation: 113747
The problem with your code is with the NSMutableAttributedStringRef
. Use an NSMutableAttributedString
instead:
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)];
Upvotes: 0
Reputation: 3907
Just see this. may be useful for you :
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];
Upvotes: 1