gpt4 book ai didi

iphone - 我可以在 iOS 的 Core Text 中使用 NSAttributedString 吗?

转载 作者:太空狗 更新时间:2023-10-30 03:26:15 38 4
gpt4 key购买 nike

我正在尝试找出如何获取 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);

但是当我尝试这样做时,它会抛出错误:

Passing argument 1 of 'CTFramesetterCreateWithAttributedString' from incompatible pointer type

CFAttributedString 和 NSAttributedString 是“免费桥接”吗?我在某处读到这只在 OSX 上是正确的,但 Apple 在他们的演示中就是这样做的......

谢谢!

:-乔

最佳答案

您可以下载WWDC10源代码here .此外,使用免费桥接并将您的 stringToDraw 显式转换为 CFAttributedStringRef

关于iphone - 我可以在 iOS 的 Core Text 中使用 NSAttributedString 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3768801/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com