Question

I am fairly new to Core Text but have been getting on well, however I'm having trouble adjusting the width of a tab.

Currently I'm using this code which I have written by looking at the documentation and mailing list:

    CFIndex theNumberOfSettings = 1;

    CFIndex i = 0; 
    CTTextTabRef tabArray[1]; 
    CTTextAlignment align = 0; 
    CGFloat location = 80; 
    for (;i < 1; i++ ) { 
        tabArray[i] = CTTextTabCreate( align, location, NULL ); 
    }       
    CFArrayRef tabStops = CFArrayCreate( kCFAllocatorDefault, (const void**) tabArray, 1, &kCFTypeArrayCallBacks );     
    for (;i < 1; i++ ) { CFRelease( tabArray[i] ); } 

    CTParagraphStyleSetting theSettings[1] =
    {
        { kCTParagraphStyleSpecifierTabStops, sizeof(CFArrayRef), &tabStops },
    };

    CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(theSettings, theNumberOfSettings);
    [self.attributedString addAttribute:(NSString *)kCTParagraphStyleAttributeName 
                                  value:(id)paragraphStyle
                                  range:range];

By setting the value of location I am able to adjust the width of the tab however this only works for the first tab created after that it resets to a different width which is very small comparatively.

Why is it doing this?

Was it helpful?

Solution

I would imagine the issue is all your tabs are created with the exact same location. Each one should probably be a multiple of 80, rather than being exactly 80.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top