我正在复习旧的 obj-c 教程并且很难理解 obj-c 代码。他们显然已被弃用。 我已经研究了其他 stackoverflow 问题,但我仍然无法弄清楚,因为没有一个不在 Swift 中。
CGSize textSize = [text sizeWithFont:textFont constrainedToSize:CGSizeMake(printableFrame.size.width, CGFLOAT_MAX) lineBreakMode:UILineBreakModeWordWrap];
CGRect textFrame = CGRectMake(printableFrame.origin.x, currentY, textSize.width, textSize.height);
如何将上述代码转换为 Swift?
最佳答案
该方法已被弃用,取而代之的是 sizeWithAttributes。
Replacement for deprecated sizeWithFont: in iOS 7?
要转换为 swift,不幸的是,看起来您必须在代码中使用 NSString
CGSize sizeWithAttributes in Swift
干净,但这会影响性能,因此如果这些行被调用很多,您可能需要寻找其他解决方案。
关于ios - 将 sizeWithFont 方法转换为 Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35429167/