Search code examples
iphoneios5uilabelcore-text

Adding space in text using core text in TTTAtributedLabel


I am using TTTAtributedLabel in my app to make text bold and remaining as it is using custom fonts. Now I want to add some space of 5px between the bold and non bold text. How can I do this? I want to add space after 1.JANUAR 1934.

enter image description here

Thanks in advance.


Solution

  • using CTRunDelegate, and add it to your ns-attributed-string,

      CTRunDelegateCallbacks callbacks;
      callbacks.version = kCTRunDelegateCurrentVersion;
      callbacks.getAscent = ascentCallback;
      callbacks.getDescent = descentCallback;
      callbacks.getWidth = widthCallback;
      callbacks.dealloc = deallocCallback;
      spaceRunDelegate = CTRunDelegateCreate(&callbacks, NULL);
    
      spacingAttrs = [[NSDictionary dictionaryWithObjectsAndKeys:
                    (id)spaceRunDelegate, 
                    (NSString*)kCTRunDelegateAttributeName,nil] retain];
    
      //add the attr to your ns-attributed-string