开发者

Want to set Font of document (.doc) in iOS

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];
开发者_Go百科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 .doc file on iOS.


As per doc

NSFont - Available in Mac OS X v10.0 and later.

Use Core Text insted:

Core Text is an advanced, low-level technology for laying out text and handling fonts. It is designed for high performance and ease of use. The Core Text API, introduced in Mac OS X v10.5, is accessible from all Mac OS X application environments. It is also available in iOS 3.2.

For instance use CTFont instead of NSFont

For the core text guide go here

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜