文本绘制附加选项NSStringDrawingOptions的解释

本博客介绍了SwiftUI框架中用于支持iOS平台下字符串绘制的API,包括如何使用NSAttributedString对象进行风格化字符串的绘制、计算字符串的大小和度量等操作。详细解释了默认坐标系统、字符串内容绘制方向及如何正确定位字符串内容。同时强调了在不同线程使用相关方法时需要注意的上下文共享问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考:https://developer.apple.com/library/ios/documentation/UIKit/Reference/NSAttributedString_UIKit_Additions/index.html#//apple_ref/c/tdef/NSStringDrawingOptions

The UIKit framework adds methods to NSAttributedString to support the drawing of styled strings and to compute the size and metrics of a string prior to drawing. None of these methods affects the contents of the object itself, only how it is drawn on screen.

UIKit框架增加了方法NSAttributedString支持风格的字符串的绘制和计算之前绘制一个字符串的大小和度量.这些方法没有影响对象本身,它是仅绘制方式在屏幕上的内容。(只有他是在屏幕上如何绘制的)

By default, strings are drawn using the native coordinate system of iOS, where content is drawn down and to the right from the specified origin point. Whenever you are positioning string content, you should keep this orientation in mind and use the upper-left corner of the string’s bounding box as the origin point for drawing. 

默认情况下,字符串使用iOS本地坐标系统来绘制,其中内容被下拉并且在指定原点右边的本地坐标系开始绘制.当你定位的字符串的内容,你应该保持这个方向考虑,使用字符串的边框的左上角为原点进行绘制

You may use the methods described in this class extension from secondary threads in your app and not just from the main thread. However, if you use any of the methods that support an NSStringDrawingContextobject, you must not share contexts across threads or dispatch queues.

你可以使用这个类拓展中声明的方法,从你应用程序辅助线程而不仅仅是主线程.但是,如果你使用任何支持的NSStringDrawingContext对象的方法,你一定不能共享跨线程或调度队列上下文
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值