2015-07-14 3 views

Antwort

1

Sie müssen auch wissen, was die ursprüngliche Schriftgröße ist, aber ich denke, man es in irgendeiner Weise

Das heißt finden, die folgende func verwenden, um die tatsächliche Schriftgröße zu entdecken:

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) 
Verwandte Themen