Swift 4 and iOS sizeWithFont ( sizeWithFont now deprecated) @Sanjit Saluja answer:
// Get the size of the text with no scaling (one line) let sizeOneLine: CGSize = label.text!.size(withAttributes: [NSAttributedStringKey.font: label.font]) // Get the size of the text enforcing the scaling based on label width let sizeOneLineConstrained: CGSize = label.text!.boundingRect(with: label.frame.size, options: .usesLineFragmentOrigin, attributes: [NSAttributedStringKey.font: label.font], context: nil).size // Approximate scaling factor let approxScaleFactor: CGFloat = sizeOneLineConstrained.width / sizeOneLine.width // Approximate new point size let approxScaledPointSize: CGFloat = approxScaleFactor * label.font.pointSize
source share