2010-07-14 5 views
7

나는 CTRunDelegate을 사용해야하는 iPad 응용 프로그램을 개발 중입니다. 필요한 모든 콜백을 정의했습니다. 즉, CTRunDelegateGetAscentCallback, CTRunDelegateGetDescentCallback, CTRunDelegateGetWidthCallback입니다. 내가 만드는 CTRunDelegateRef 개체를 사용하는 방법을 모른다. 지금 무슨 일이 일어나고 있는지 콜백이 불리지 않을 것입니다.iPad에서 CTRunDelegate를 사용하는 방법은 무엇입니까?

이 점에 대한 모든 참고 사항은 높이 평가 될 것입니다.

고지.

답변

11

실행 대리자는 특성 문자열의 문자 범위에 대한 특성으로 추가해야합니다. 을 참조하십시오. 드로잉 할 때, Core Text는 콜백을 호출하여 해당 문자의 크기를 결정합니다.

업데이트

이 간단한 텍스트 그리기보기위한 샘플 코드이다 (여기에는 메모리 관리 코드가 없다는 것을 참고).

@implementation View 

/* Callbacks */ 
void MyDeallocationCallback(void* refCon){ 

} 
CGFloat MyGetAscentCallback(void *refCon){ 
    return 10.0; 
} 
CGFloat MyGetDescentCallback(void *refCon){ 
    return 4.0; 
} 
CGFloat MyGetWidthCallback(void* refCon){ 
    return 125; 
} 

- (void)drawRect:(CGRect)rect { 
    // create an attributed string 
    NSMutableAttributedString * attrString = [[NSMutableAttributedString alloc]     initWithString:@"This is my delegate space"]; 

    // create the delegate 
    CTRunDelegateCallbacks callbacks; 
    callbacks.version = kCTRunDelegateVersion1; 
    callbacks.dealloc = MyDeallocationCallback; 
    callbacks.getAscent = MyGetAscentCallback; 
    callbacks.getDescent = MyGetDescentCallback; 
    callbacks.getWidth = MyGetWidthCallback; 
    CTRunDelegateRef delegate = CTRunDelegateCreate(&callbacks, NULL); 

    // set the delegate as an attribute 
    CFAttributedStringSetAttribute((CFMutableAttributedStringRef)attrString, CFRangeMake(19, 1), kCTRunDelegateAttributeName, delegate); 

    // create a frame and draw the text 
    CTFramesetterRef frameSetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attrString); 
    CGMutablePathRef path = CGPathCreateMutable(); 
    CGPathAddRect(path, NULL, rect); 
    CTFrameRef frame = CTFramesetterCreateFrame(frameSetter, CFRangeMake(0, attrString.length), path, NULL); 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextSetTextMatrix(context, CGAffineTransformIdentity); 
    CGContextSetTextPosition(context, 0.0, 0.0); 
    CTFrameDraw(frame, context); 
} 

@end 

텍스트의 "위임자"와 "공백"사이의 공백 문자 크기는 실행 위임자가 제어합니다.

+0

나는 이미 그렇게했지만 도움이되지 않습니다. 문서 자체는 CTRunDelegate에 대한 많은 정보를 제공하지 않습니다. CTRunDelegate에 대한 샘플 코드가 있다면 큰 도움이 될 것입니다. – tek3

+0

당신의 대답을보기 전에 나는 답을 얻었지만 당신은 저에게 올바른 대답을 주려고 노력했습니다. 그래서이 현상금이 당신에게갑니다. 귀하의 응답에 대해 많이 고맙습니다. – tek3

+0

안녕하세요, 신청서에 도움이 필요합니다. 나 좀 도와 줄래? – tek3

관련 문제