Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should add your run delegate as an attribute for a range of characters in your attributed string. See <a href="http://developer.apple.com/iphone/library/documentation/Carbon/Reference/CoreText_StringAttributes_Ref/Reference/reference.html#//apple_ref/doc/c_ref/kCTRunDelegateAttributeName" rel="noreferrer">Core Text String Attributes</a>. When drawing, Core Text will call your callbacks to get the sizing of that characters.</p> <p><strong>Update</strong></p> <p>This is a sample code for a view drawing a simple text (Note that there's no memory management code here).</p> <pre><code>@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(&amp;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 </code></pre> <p>The size of the space character between "delegate" and "space" in the text are controlled by the run delegate.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload