Hi I am using following code in the MAC application for setting font of document file. But I didn’t get any success to set font in iOS application.
NSFont *docFont = [NSFont fontWithName:@"Times New Roman" size:12];
NSDictionary *docAttributes = [NSDictionary dictionaryWithObjectsAndKeys: docFont,NSFontAttributeName,nil];
NSAttributedString *docAttributed = [[NSAttributedString alloc] initWithString:doc attributes:gradeDocAttributes];
NSData *docData = [docAttributed docFormatFromRange:NSMakeRange(0, [gradeDoc length]) documentAttributes:nil];
// write docData to a file
[docData writeToFile:path atomically:YES];
how can I implement same functionality in iOS application.
I am able to write file. following code I used for write file in my iOS app. But no success for setting font of it.
NSString *doc=[self calculatedResult];
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString* path;
NSString* str =[NSString stringWithFormat:@"%@",self.objStudent.name];
str = [str stringByAppendingFormat:@".doc"];
path = [[paths objectAtIndex:0] stringByAppendingPathComponent:str];
[doc writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:nil];
The method
docFormatFromRange:documentAttributes:is defined in “NSAttributedString Application Kit Additions” (as found here: http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSAttributedString_AppKitAdditions/Reference/Reference.html).It’s only available on AppKit (OS X) but not in the Core Text implementation of iOS. So there is no way to create a
.docfile on iOS.