mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2024-12-11 08:56:54 +01:00
26 lines
937 B
Swift
26 lines
937 B
Swift
//
|
|
// String-Extensions.swift
|
|
// 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)
|
|
let boundingBox = self.boundingRect(with: constraintRect, options: [.usesLineFragmentOrigin, .usesFontLeading], attributes: [NSAttributedString.Key.font: font], context: nil)
|
|
return ceil(boundingBox.height)
|
|
}
|
|
|
|
func width(withConstrainedHeight height: CGFloat, font: UIFont) -> CGFloat {
|
|
let constraintRect = CGSize(width: .greatestFiniteMagnitude, height: height)
|
|
let boundingBox = self.boundingRect(with: constraintRect, options: [.usesLineFragmentOrigin, .usesFontLeading], attributes: [NSAttributedString.Key.font: font], context: nil)
|
|
return ceil(boundingBox.width)
|
|
}
|
|
|
|
}
|