mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-11-27 15:54:30 +00:00
24 lines
835 B
Swift
24 lines
835 B
Swift
//
|
|
// StringSize+Extensions.swift
|
|
// NetNewsWire-iOS
|
|
//
|
|
// Created by Brent Simmons on 6/22/26.
|
|
//
|
|
|
|
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: [.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: [.font: font], context: nil)
|
|
return ceil(boundingBox.width)
|
|
}
|
|
}
|