Tôi đang cố gắng tìm ra cách lấy NSAttributedString và sử dụng nó trong Core Text trên iPad. Tôi đã xem một trong những video WWDC (110) trong đó có các slide (nhưng không có mã nguồn) và nó mô tả làm thế nào để tạo ra một NSAttributedString, sau đó chỉ cần đặt nó vào một CTFramesetterRef:Tôi có thể sử dụng NSAttributedString trong Core Text trong iOS không?
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);
Nhưng khi tôi cố gắng này, nó ném lỗi:
Passing argument 1 of 'CTFramesetterCreateWithAttributedString' from incompatible pointer type
CFAttributedString và NSAttributedString 'cầu nối miễn phí'? Tôi đã đọc ở đâu đó rằng điều này chỉ đúng trên OSX, nhưng đây là cách Apple làm điều đó trong bản demo của họ ...
Cảm ơn!
: -Joe
là bạn có thể nhận được gạch dưới rải rác xuất hiện? Tôi chỉ nhận được gạch chân đơn đơn giản dưới văn bản. – learner2010