UIKit's [NSString sizeWithFont:constrainedToSize:] in AppKit

前端 未结 6 1279
旧巷少年郎
旧巷少年郎 2021-01-02 22:47

Is there any equivalent method in AppKit (for Cocoa on Mac OS X) that does the same thing as UIKit\'s [NSString sizeWithFont:constrainedToSize:]?

If not

6条回答
  •  庸人自扰
    2021-01-02 22:51

    If you want to constrain the string to a certain size, you use -[NSString boundingRectWithSize:options:attributes:]. The .size of the returned NSRect is the size you're looking for.

提交回复
热议问题