2019-04-15 22:03:05 +02:00
|
|
|
//
|
2019-04-19 14:49:35 +02:00
|
|
|
// String-Extensions.swift
|
2019-04-15 22:03:05 +02:00
|
|
|
// NetNewsWire
|
|
|
|
//
|
|
|
|
// Created by Maurice Parker on 4/8/19.
|
|
|
|
// Copyright © 2019 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
|
|
|
extension String {
|
|
|
|
|
|
|
|
func height(withConstrainedWidth width: CGFloat, font: UIFont) -> CGFloat {
|
|
|
|
let constraintRect = CGSize(width: width, height: .greatestFiniteMagnitude)
|
2019-04-29 21:40:14 +02:00
|
|
|
let boundingBox = self.boundingRect(with: constraintRect, options: [.usesLineFragmentOrigin, .usesFontLeading], attributes: [NSAttributedString.Key.font: font], context: nil)
|
2019-04-15 22:03:05 +02:00
|
|
|
return ceil(boundingBox.height)
|
|
|
|
}
|
|
|
|
|
|
|
|
func width(withConstrainedHeight height: CGFloat, font: UIFont) -> CGFloat {
|
|
|
|
let constraintRect = CGSize(width: .greatestFiniteMagnitude, height: height)
|
2019-04-29 21:40:14 +02:00
|
|
|
let boundingBox = self.boundingRect(with: constraintRect, options: [.usesLineFragmentOrigin, .usesFontLeading], attributes: [NSAttributedString.Key.font: font], context: nil)
|
2019-04-15 22:03:05 +02:00
|
|
|
return ceil(boundingBox.width)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|