所以我有一个NSAttributedString我想bullet point在一部分文本的开头插入一个。我怎样才能做到这一点?CTPAragraphStyle显示文字时,如何创建一个创建该项目符号的点?
NSAttributedString
bullet point
CTPAragraphStyle
编辑:* 应该在 iOS 上可用 *
简单一点:[mutableAttributedString insertAttributedString:@“•\ t” atIndex:0];
难点。遵循以下内容。(这是从一个较大的项目中摘录的,但可能会为您提供一个不错的开始。)
NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithString:@"•\texample bullet fill out the text to check what happens on the second line and make sure it is lining up OK"]; CTTextAlignment alignment = kCTLeftTextAlignment; CGFloat paragraphSpacing = 0.0; CGFloat paragraphSpacingBefore = 0.0; CGFloat firstLineHeadIndent = 15.0; CGFloat headIndent = 30.0; CGFloat firstTabStop = 15.0; // width of your indent CGFloat lineSpacing = 0.45; CTTextTabRef tabArray[] = { CTTextTabCreate(0, firstTabStop, NULL) }; CFArrayRef tabStops = CFArrayCreate( kCFAllocatorDefault, (const void**) tabArray, 1, &kCFTypeArrayCallBacks ); CFRelease(tabArray[0]); CTParagraphStyleSetting altSettings[] = { { kCTParagraphStyleSpecifierLineSpacing, sizeof(CGFloat), &lineSpacing}, { kCTParagraphStyleSpecifierAlignment, sizeof(CTTextAlignment), &alignment}, { kCTParagraphStyleSpecifierFirstLineHeadIndent, sizeof(CGFloat), &firstLineHeadIndent}, { kCTParagraphStyleSpecifierHeadIndent, sizeof(CGFloat), &headIndent}, { kCTParagraphStyleSpecifierTabStops, sizeof(CFArrayRef), &tabStops}, { kCTParagraphStyleSpecifierParagraphSpacing, sizeof(CGFloat), ¶graphSpacing}, { kCTParagraphStyleSpecifierParagraphSpacingBefore, sizeof(CGFloat), ¶graphSpacingBefore} }; CTParagraphStyleRef style; style = CTParagraphStyleCreate( altSettings, sizeof(altSettings) / sizeof(CTParagraphStyleSetting) ); if ( style == NULL ) { NSLog(@"*** Unable To Create CTParagraphStyle in apply paragraph formatting" ); return; } [string addAttributes:[NSDictionary dictionaryWithObjectsAndKeys:(NSObject*)style,(NSString*) kCTParagraphStyleAttributeName, nil] range:NSMakeRange(0,[string length])]; CFRelease(tabStops); CFRelease(style);
您需要包括CoreText框架,然后导入CoreText / CoreText.h