29 lines
643 B
Swift
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))
|
|
}
|
|
}
|