NSAttributedString第一行缩进 [英] NSAttributedString end of first line indent

查看:199
本文介绍了NSAttributedString第一行缩进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆