Files
yingmeng-ios-switf/yinmeng-ios/Modules/Chat/Tool/ChatAttributeTool.swift
2024-02-27 23:34:55 +08:00

29 lines
643 B
Swift

//
// ChatAttributeTool.swift
// yinmeng-ios
//
// Created by MaiMang on 2024/2/27.
//
import Foundation
public class ChatAttributeTool {
// size
public class func boundingRect(attribute: NSAttributedString, font: UIFont, maxSize: CGSize) -> CGSize {
if attribute.length == 0 {
return CGSize.zero
}
var sizeRec = attribute.boundingRect(
with: maxSize,
options: [.usesLineFragmentOrigin, .usesFontLeading],
context: nil
).size
if attribute.length > 0, sizeRec.width == 0, sizeRec.height == 0 {
sizeRec = maxSize
}
return CGSize(width: ceil(sizeRec.width), height: ceil(sizeRec.height))
}
}