NSAttributedString第一行缩进 [英] NSAttributedString end of first line indent
问题描述
我想将UITextView
中的第一行从第一行的右侧缩进到UITextView
中.
I want to have the first line in an NSAttributedString
for a UITextView
indented from the right side on the first line.
因此,NSParagraphStyle
中的firstLineHeadIndent
将使左侧的第一行缩进.我想做同样的事情,但要从我的UITextView
右边开始.
So the firstLineHeadIndent
in NSParagraphStyle
will indent the first line from the left. I want to do the same thing but from the right in my UITextView
.
这是我希望如何包装文字的屏幕截图.
Here's a screenshot of how I want the text to wrap.
推荐答案
设置文本页边距文章如下:
如您所见,没有内置机制可以使第一行尾部缩进.
As you can see, there's no built-in mechanism to have a first line tail indent.
但是,NSTextContainer
具有属性exclusionPaths
,该属性表示应从其中排除文本的矩形区域的一部分.因此,您可以在右上角添加一条路径,以防止文本进入该位置.
However, NSTextContainer
has a property exclusionPaths
which represents parts of its rectangular area from which text should be excluded. So, you could add a path for the upper-right corner to prevent text from going there.
UIBezierPath* path = /* compute path for upper-right portion that you want to exclude */;
NSMutableArray* paths = [textView.textContainer.exclusionPaths mutableCopy];
[paths addObject:path];
textView.textContainer.exclusionPaths = paths;
这篇关于NSAttributedString第一行缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!