Last active
December 14, 2017 00:28
-
-
Save acrookston/70154fc790ffc0a4c99811995295f26d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// LICENSE: MIT | |
// Created by Andrew C on 4/25/17. | |
// Copyright © 2017 Andrew Crookston. All rights reserved. | |
// | |
class TopAlignedLabel: UILabel { | |
override func drawText(in rect: CGRect) { | |
if let string = text as NSString? { | |
let size = string.boundingRect(with: CGSize(width: self.frame.width,height: CGFloat.greatestFiniteMagnitude), | |
options: NSStringDrawingOptions.usesLineFragmentOrigin, | |
attributes: [NSFontAttributeName: font], | |
context: nil).size | |
super.drawText(in: CGRect(x: 0, y: 0, width: self.frame.width, height: ceil(size.height))) | |
} else { | |
super.drawText(in: rect) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment