فهرست منبع

Merge branch 'master' of https://git.yishihui.com/wenweiwei/BFCommonKit

* 'master' of https://git.yishihui.com/wenweiwei/BFCommonKit:
  1.修改时间显示规则
huzhiqiang 3 سال پیش
والد
کامیت
0d9438d874
1فایلهای تغییر یافته به همراه10 افزوده شده و 5 حذف شده
  1. 10 5
      BFCommonKit/Classes/BFUtility/PQCommonMethodUtil.swift

+ 10 - 5
BFCommonKit/Classes/BFUtility/PQCommonMethodUtil.swift

@@ -335,11 +335,16 @@ public func jsonStringToArray(jsonString: String) -> [Any]? {
 ///   - font: <#font description#>
 ///   - size: <#size description#>
 /// - Returns: <#description#>
-public func sizeWithText(text: String, font: UIFont, size: CGSize) -> CGSize {
-    let attributes = [NSAttributedString.Key.font: font]
+public func sizeWithText(attributedText: NSMutableAttributedString? = nil,text: String, font: UIFont, size: CGSize) -> CGSize {
     let option = NSStringDrawingOptions.usesLineFragmentOrigin
-    let rect: CGRect = text.boundingRect(with: size, options: option, attributes: attributes, context: nil)
-    return rect.size
+    if attributedText != nil {
+        let rect: CGRect = attributedText?.boundingRect(with: size, options: option, context: nil) ?? CGRect.init(origin: CGPoint.zero, size: size)
+        return rect.size
+    } else {
+        let attributes = [NSAttributedString.Key.font: font]
+        let rect: CGRect = text.boundingRect(with: size, options: option, attributes: attributes, context: nil)
+        return rect.size
+    }
 }
 
 /// 根据行数计算字符串大小
@@ -696,7 +701,7 @@ public func updateTimeToCurrenTime(timeInterval: TimeInterval) -> String {
     let date = NSDate(timeIntervalSince1970: timeInterval)
     let dfmatter = DateFormatter()
     // yyyy-MM-dd HH:mm:ss
-    dfmatter.dateFormat = "yyyy年M月d日"
+    dfmatter.dateFormat = "yyyy年M月d日 HH:mm"
     
     var dfmatterStr = dfmatter.string(from: date as Date)