Sam*_*Sam 5 objective-c uitextview nsattributedstring ios
在我的应用程序中,我需要以不同的方式对齐所有段落。
比如,第一段的headIndent是 0.0f,然后第二段的 10.0f 和第三段的 3.0f。
我将所有段落样式都赋予textview.attributedText。而且只用了一种风格。
这里整个文本将通过 Typing 动态出现。表示用户何时将在文本视图中输入。所以,没有静态字符串可以做到这一点。
我通过这个将所有字符放在 UITextView 中......
UIFont *fontBold = [UIFont fontWithName:@"Helvetica-Bold" size:15];
attributesHelveticaBold = @{NSFontAttributeName :fontBold};
UIFont *fontNormal = [UIFont fontWithName:@"HelveticaNeue-Light" size:15];
attributesNormal = @{NSFontAttributeName :fontNormal};
if (varBold== 1) {
[textView setTypingAttributes:attributesHelveticaBold];
}
else {
[textView setTypingAttributes:attributesNormal];
}
Run Code Online (Sandbox Code Playgroud)
我想在文本视图中获得这种结果

当我打字时,打字也变慢了。
但我想我会解决这个问题,但现在我坚持这个对齐问题。
当项目符号出现和不同的文本出现时如何做。
任何类型的链接、代码、教程都会有很大帮助......
- - - - - 编辑 : - - - - -
请查看Evernote的应用程序。
我需要在我的应用程序中做完全相同的事情。用于在子弹来时对齐第二、第三等行。
-------- 搜索后编辑:-------
我为此搜索了太多,但通过谷歌搜索没有找到任何东西。
所以,现在我问是否有人现在关于如何为段落提供任何段落样式或任何属性样式,并在文本视图中保持原样,然后在第二段上执行其他段落样式。这时第一段不会通过抛出“shouldChangeTextInRange”方法。
是的,无论我说什么,这都令人困惑。
所以我一般地解释它......
如果用户设置文本视图的第一段的 headIndent=7.0f 那么当用户输入下一段并设置 headIndent = 13.0f 时,第一段将保持在 textview 中的原样,并且只运行段落将进入一章(意味着在方法中)。
现在我在shouldChangeTextInRange方法中做这些事情来为每个段落做样式。
varStaringPointOfString = 0;
varEndingPointOfString = 0;
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:@"\t•\t"])
{
[[textView textStorage] addAttribute:NSParagraphStyleAttributeName value:paragraphStyleForBullet range:NSMakeRange(varEndingPointOfString, strtostoreLength.length)];
}
else
{
[[textView textStorage] addAttribute:NSParagraphStyleAttributeName value:paragraphStyleNormal range:NSMakeRange(varEndingPointOfString, strtostoreLength.length)];
}
varEndingPointOfString = varStaringPointOfString;
strtostoreLength =@"";
}
Run Code Online (Sandbox Code Playgroud)
但由此打字速度变得非常缓慢。
尝试这个:
NSMutableParagraphStyle *paragraphStyle = [[[NSMutableParagraphStyle alloc] init];
[paragraphStyle setFirstHeadLineHeadIndent:firstLineIndend]; //Only the first line
[paragraphStyle setHeadIndent:headIndent]; //The rest of the lines, except the first one
[yourAttributedString addAttribute:NSParagraphStyleAttributeName
value:paragraphStyle
range:paragraphRange];
Run Code Online (Sandbox Code Playgroud)
对于要点来说,这是不同的。您需要找到项目符号点在哪里,并相应地设置另一个缩进。
| 归档时间: |
|
| 查看次数: |
2680 次 |
| 最近记录: |