GBA002/Delta/Extensions/UILabel+FontSize.swift
Riley Testut 8f572fd1c8 Added basic PauseViewController implementation
Also, happy Boxing Day! Hope you're enjoying your new iPad Pro future Riley :)
2015-12-26 02:23:30 -06:00

29 lines
864 B
Swift

//
// UILabel+FontSize.swift
// Delta
//
// Created by Riley Testut on 12/25/15.
// Copyright © 2015 Riley Testut. All rights reserved.
//
import UIKit
internal extension UILabel
{
var currentScaleFactor: CGFloat
{
guard let text = self.text else { return 1.0 }
let context = NSStringDrawingContext()
context.minimumScaleFactor = self.minimumScaleFactor
// Using self.attributedString returns incorrect calculations, so we create our own attributed string
let attributedString = NSAttributedString(string: text, attributes: [NSFontAttributeName: self.font])
attributedString.boundingRectWithSize(self.bounds.size, options: [.UsesLineFragmentOrigin, .UsesFontLeading], context: context)
let scaleFactor = context.actualScaleFactor
return scaleFactor
}
}