iOS: How do you measure the width and height of a string using Quartz?

前端 未结 2 1393
甜味超标
甜味超标 2021-01-31 05:33

Before I ask my questions, this is from Apple\'s documentation re: how to determine the width of a string using Quartz:

If text measurements are important

2条回答
  •  庸人自扰
    2021-01-31 05:50

    When performing drawing operations on threads other than the UI thread, you must use the technique you described. This is especially important to note when using things like CATiledLayer, which performs it's rendering asynchronously on background threads, or when drawing custom graphics in the background for any other reason.

    I agree with PGB when you're doing "simple" graphics and you are guaranteed to be running on the main thread. However, sizeWithFont is doing the same thing as the technique you described - it's simply doing it for you using UIGraphicsGetCurrentContext().

提交回复
热议问题