Creating Paragraphs using CoreText in iphone/ipad

Discussion in 'iOS Programming' started by arnieterm, Jul 8, 2010.

  1. arnieterm macrumors regular

    Aug 28, 2008
    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.
    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(
    												  (const void **)&keys, 
    												  (const void **)&values,
    												  sizeof(keys) / sizeof(keys[0]), 
    		[htmlContent addAttributes:(NSDictionary*) paraAttribute range: applyToRange];
    here htmlContent is the NSMutableAttributedString. What is wrong with this code? Any idea?

Share This Page