Open churabou opened 6 years ago
ラベル
func increaseFontSize(_ newBounds: CGRect) {
var fontSize: CGFloat = label.fontSize
var attributedText = NSAttributedString(string: label.text!,
attributes: [.font: UIFont(name: label.font.fontName, size: fontSize) as Any])
let size = CGSize(width: CGFloat.greatestFiniteMagnitude,
height: CGFloat.greatestFiniteMagnitude)
var requiredSize = attributedText.boundingRect(with: size, options: [], context: nil)
while requiredSize.width < newBounds.width {
fontSize += 0.5
attributedText = NSAttributedString(string: label.text!, attributes: [.font:
UIFont(name: label.font.fontName, size: fontSize) as Any])
requiredSize = attributedText.boundingRect(with: size, options: [], context: nil)
}
label.updateFontsize(to: fontSize)
}