NSString boundingRectWithSize returning unnecessarily tall height

前端 未结 4 1563
盖世英雄少女心
盖世英雄少女心 2021-01-30 18:12

When using [NSString boundingRectWithSize:options:attributes] the size of the rect that is returned is taller than I would expect for certain strings. The height re

4条回答
  •  别跟我提以往
    2021-01-30 18:55

    Swift 3+ solution based on omz's answer:

    let string: NSString = "test"
    let maxSize = NSSize(width: CGFloat.greatestFiniteMagnitude, height: .greatestFiniteMagnitude)
    let boundingRect = string.boundingRect(with: maxSize, options: .usesDeviceMetrics, attributes: )
    

提交回复
热议问题