Created
August 14, 2017 21:05
-
-
Save rosem/fbc148cc52caf3b0057305e30be54d11 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
// | |
// NSAttributedString+Extension.swift | |
// Contacts | |
// | |
// Created by Michael Rose on 8/9/17. | |
// Copyright © 2017 Mike Rose. All rights reserved. | |
// | |
import UIKit | |
extension NSAttributedString { | |
func height(containerWidth: CGFloat) -> CGFloat { | |
let rect = self.boundingRect(with: CGSize.init(width: containerWidth, height: CGFloat.greatestFiniteMagnitude), options: [.usesLineFragmentOrigin, .usesFontLeading], context: nil) | |
return ceil(rect.size.height) | |
} | |
func width(containerHeight: CGFloat) -> CGFloat { | |
let rect = self.boundingRect(with: CGSize.init(width: CGFloat.greatestFiniteMagnitude, height: containerHeight), options: [.usesLineFragmentOrigin, .usesFontLeading], context: nil) | |
return ceil(rect.size.width) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment