2015-07-14 8 views

Odpowiedz

1

Trzeba także wiedzieć, jaki jest oryginalny rozmiar czcionki, ale myślę, że można go znaleźć w jakiś sposób

że wymieniony, należy użyć następującego func odkryć rzeczywisty rozmiar czcionki:

func getFontSizeForLabel(_ label: UILabel) -> CGFloat { 
    let text: NSMutableAttributedString = NSMutableAttributedString(attributedString: label.attributedText!) 
    text.setAttributes([NSFontAttributeName: label.font], range: NSMakeRange(0, text.length)) 
    let context: NSStringDrawingContext = NSStringDrawingContext() 
    context.minimumScaleFactor = label.minimumScaleFactor 
    text.boundingRect(with: label.frame.size, options: NSStringDrawingOptions.usesLineFragmentOrigin, context: context) 
    let adjustedFontSize: CGFloat = label.font.pointSize * context.actualScaleFactor 
    return adjustedFontSize 
} 

//actualFontSize is the size, in points, of your text 
let actualFontSize = getFontSizeForLabel(label) 

//with a simple calc you'll get the new Scale factor 
print(actualFontSize/originalFontSize*100) 
Powiązane problemy