Creating Paragraphs using CoreText in iphone/ipad

Discussion in 'iPhone/iPad Programming' started by arnieterm, Jul 8, 2010.

  1. macrumors regular

    Joined:
    Aug 28, 2008
    #1
    Hi all
    In order to create multiple paragraph(s) using CoreText do we need to set CTFrameSetter seperately for each paragraph? I am trying to apply settings for various paragraph like alignment, paragraph spacing etc but it does not apply. Though I am successfully able to apply font to them.
    Code:
    
    CGFloat ls = height;
    		CTParagraphStyleSetting setting;
    		setting.spec = kCTParagraphStyleSpecifierParagraphSpacing;
    		setting.valueSize = sizeof(CGFloat);
    		setting.value = &ls;
    		CFIndex theNumberOfSettings = 1;		
    		CTParagraphStyleSetting settings[1] = {
    			//{kCTParagraphStyleSpecifierAlignment, sizeof(alignment), &alignment},
    			{kCTParagraphStyleSpecifierParagraphSpacing, sizeof(CGFloat), &ls},			
    		};
    		//CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(settings, sizeof(settings) / sizeof(settings[0]));
    		CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(settings, theNumberOfSettings);
    		
    		CFStringRef keys[] = { kCTParagraphStyleAttributeName };
    		CFTypeRef values[] = { paragraphStyle };
    		CFDictionaryRef paraAttribute = CFDictionaryCreate(
    												  NULL, 
    												  (const void **)&keys, 
    												  (const void **)&values,
    												  sizeof(keys) / sizeof(keys[0]), 
    												  &kCFTypeDictionaryKeyCallBacks, 
    												  &kCFTypeDictionaryValueCallBacks
    												  );
    		[htmlContent addAttributes:(NSDictionary*) paraAttribute range: applyToRange];
    		//CFRelease(paragraphStyle);
    		//CFRelease(attr);
    
    
    here htmlContent is the NSMutableAttributedString. What is wrong with this code? Any idea?
    Thanks
     

Share This Page