jow*_*wie 10 iphone objective-c ipad core-text
我正在尝试研究如何获取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);
Run Code Online (Sandbox Code Playgroud)
但是当我尝试这个时,它会抛出错误:
从不兼容的指针类型传递'CTFramesetterCreateWithAttributedString'的参数1
CFAttributedString和NSAttributedString'免费桥接'?我已经在某处读过,这只适用于OSX,但这就是Apple在他们的演示中如何做到这一点......
谢谢!
:-Joe
| 归档时间: |
|
| 查看次数: |
14425 次 |
| 最近记录: |