Jak korzystać z CTRunDelegate na iPadzie?

Jestem twórcą aplikacji na iPada, w której muszę używać CTRunDelegate. Zdefiniowałem wszystkie wymagane wywołania zwrotne, mianowicie CTRunDelegateGetAscentCallback , CTRunDelegateGetDescentCallback , CTRunDelegateGetWidthCallback. Nie wiem jak używać CTRunDelegateRef obiektu, który tworzę. W tej chwili to, co się dzieje, to to, że moje telefony zwrotne nie są wywoływane.

Wszelkie wskazówki w tym zakresie będą wysoko cenione.

Thanx z góry.
Author: Peter Hosey, 2010-07-14

1 answers

Powinieneś dodać swojego delegata run jako atrybut dla zakresu znaków w przypisanym ciągu. Zobacz Podstawowe Atrybuty Ciągu Tekstowego . Podczas rysowania Core Text wywoła wywołania zwrotne, aby uzyskać Rozmiar tych znaków.

Update

Jest to przykładowy kod dla widoku rysującego prosty tekst(zauważ, że nie ma tutaj kodu zarządzania pamięcią).

@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

Wielkość znaku spacji pomiędzy "delegat" i "spacja" w tekście jest kontrolowana przez delegat biegu.

 11
Author: mohsenr,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-07-22 16:07:56