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

前端 未结 2 1428
甜味超标
甜味超标 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 06:05

    On the iPhone SDK, there's a family of methods on NSString that provide what you want.

    As of iOS 7.0, these methods are:

    - boundingRectWithSize:options:attributes:context:
    - sizeWithAttributes:
    

    On older versions of iOS we had these, now deprecated:

    – sizeWithFont:  
    – sizeWithFont:forWidth:lineBreakMode:  
    – sizeWithFont:constrainedToSize:  
    – sizeWithFont:constrainedToSize:lineBreakMode:  
    – sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode:
    

提交回复
热议问题