Skip to content

Instantly share code, notes, and snippets.

@rosem
Created August 14, 2017 21:05
Show Gist options
  • Save rosem/fbc148cc52caf3b0057305e30be54d11 to your computer and use it in GitHub Desktop.
Save rosem/fbc148cc52caf3b0057305e30be54d11 to your computer and use it in GitHub Desktop.
//
// 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