UITextView中的多个NSMutableParagraphStyle

时间:2014-04-19 06:24:55

标签: ios objective-c uitextview nsattributedstring

在我的应用中,我需要为UITextView中的每个段落显示不同的段落样式

如果用户编写的第一段 headIndent 10.0 ,那么第二段的 26.0 第三段有 7.0 第四段有 0.0 等......

如果我通过if else条件执行此操作,那么打字速度会变慢

我该怎么做?打字速度不会变慢,我可以为不同的段落设置不同的段落样式。

我正在使用 shouldChangeTextInRange 方法中的小代码来了解问题......

NSArray *sampleArrToGetattrStr = [txtViewOfNotes.text componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];

for (int i=0; i<[sampleArrToGetattrStr count]; i++) {
    NSString *strtostoreLength = [NSString stringWithFormat:@"%@",[sampleArrToGetattrStr objectAtIndex:i]];
    varStaringPointOfString = (int)strtostoreLength.length + varEndingPointOfString;

    if ([strtostoreLength hasPrefix:@"  \u2022   "])
    {
        NSLog(@"if %d == %d == %d == %lu",i,varStaringPointOfString,varEndingPointOfString,(unsigned long)strtostoreLength.length);

        paragraphStyleForBulletInNewPresMethod.headIndent=26.0;
        paragraphStyleForBulletInNewPresMethod.minimumLineHeight = 0.f;
        paragraphStyleForBulletInNewPresMethod.maximumLineHeight = 16.f;
        paragraphStyleForBulletInNewPresMethod.paragraphSpacing = 7.5;
        paragraphStyleForBulletInNewPresMethod.lineSpacing = 5.0;
        paragraphStyleForBulletInNewPresMethod.lineBreakMode=NSLineBreakByWordWrapping;
        paragraphStyleForBulletInNewPresMethod.tailIndent=305.0;

        [mutattstr1  addAttribute:NSParagraphStyleAttributeName value:paragraphStyleForBulletInNewPresMethod range:NSMakeRange(varEndingPointOfString, strtostoreLength.length)];

    }
{
        NSLog(@"else %d == %d == %d == %lu",i,varStaringPointOfString,varEndingPointOfString,(unsigned long)strtostoreLength.length);

        paragraphStyle.headIndent=0.f;
        paragraphStyle.minimumLineHeight = 0.f;
        paragraphStyle.maximumLineHeight = 16.f;
        paragraphStyle.paragraphSpacing = 7.5;
        paragraphStyle.lineSpacing = 5.0;
        paragraphStyle.lineBreakMode=NSLineBreakByWordWrapping;
        paragraphStyle.tailIndent=305.0;

        [mutattstr1  addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(varEndingPointOfString, strtostoreLength.length)];

    }

    varEndingPointOfString = varStaringPointOfString;

    strtostoreLength =@"";
}
[txtViewOfNotes setAttributedText:mutattstr1];

任何形式的帮助都会受到欢迎。

0 个答案:

没有答案