我正在尝试弄清楚如何获取 NSAttributedString 并在 iPad 上的 Core Text 中使用它。我观看了 WWDC 视频 (110) 之一,其中有幻灯片(但没有源代码),它描述了如何创建 NSAttributedString,然后将其放入 CTFramesetterRef 中:
CTFontRef helveticaBold = CTFontCreateWithName( CFSTR("Helvetica-Bold"), 24.0, NULL);
NSString* unicodeString = NSLocalizedString(@"TitleString", @"Window Title");
CGColorRef color = [UIColor blueColor].CGColor; NSNumber* underline = [NSNumber numberWithInt:kCTUnderlineStyleSingle|kCTUnderlinePatternDot];
NSDictionary* attributesDict = [NSDictionary dictionaryWithObjectsAndKeys:helveticaBold, (NSString*)kCTFontAttributeName, color, (NSString*)kCTForegroundColorAttributeName, underline, (NSString*)kCTUnderlineStyleAttributeName, nil];
NSAttributedString* stringToDraw = [[NSAttributedString alloc] initWithString:unicodeString attributes:attributesDict];
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(stringToDraw);
CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, 0), path, NULL);
CFRelease(framesetter);
CTFrameDraw(frame, context);
CFRelease(frame);
但是当我尝试这样做时,它会抛出错误:
从不兼容的指针类型传递“CTFramesetterCreateWithAttributedString”的参数 1
CFAttributedString 和 NSAttributedString 是否“免费桥接”?我在某处读到这仅适用于 OSX,但这就是 Apple 在他们的演示中所做的......
Thanks!
:-Joe
您可以下载WWDC10源代码here。此外,使用免费桥接并明确地投射您的stringToDraw
to a CFAttributedStringRef
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)