Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save quangtqag/d84d0e09ac5bda698bec40a9047f95eb to your computer and use it in GitHub Desktop.
Save quangtqag/d84d0e09ac5bda698bec40a9047f95eb to your computer and use it in GitHub Desktop.
myLabel.backgroundColor = UIColor.greenColor()
myLabel.text = "What Do I Want to Do?(Select One)"
myLabel.adjustsFontSizeToFitWidth = true
myLabel.minimumScaleFactor = 0.1
let attributes = [NSFontAttributeName : myLabel.font]
let attributedString = NSMutableAttributedString(string:textString, attributes:attributes)
let context = NSStringDrawingContext()
context.minimumScaleFactor = myLabel.minimumScaleFactor
attributedString.boundingRectWithSize(
myLabel.bounds.size,
options: .UsesLineFragmentOrigin,
context: context)
print("actual context after drawing: \(context.actualScaleFactor)")
let actualFontSize = myLabel.font.pointSize * context.actualScaleFactor
print("actualFontSize = \(actualFontSize)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment