浏览代码

Delta formatting and size adjustments

Mike 1 年之前
父节点
当前提交
4f3850766c
共有 1 个文件被更改,包括 12 次插入3 次删除
  1. 12 3
      LoopFollow/Contact/ContactImageUpdater.swift

+ 12 - 3
LoopFollow/Contact/ContactImageUpdater.swift

@@ -124,11 +124,20 @@ class ContactImageUpdater {
     ]
 
     var separateAttributes: [NSAttributedString.Key: Any] = [
-        .font: UIFont.boldSystemFont(ofSize: 160),
+        .font: UIFont.boldSystemFont(ofSize: 140),
         .foregroundColor: stale ? UIColor.gray : savedTextUIColor,
         .paragraphStyle: paragraphStyle
     ]
-
+    
+    // Format extraDelta based on the user's unit preference
+    let unitPreference = UserDefaultsRepository.units.value
+    let formattedExtraDelta: String
+    if unitPreference == "mg/dL" {
+        formattedExtraDelta = String(format: "%.0f", (extraDelta as NSString).doubleValue)
+    } else {
+        formattedExtraDelta = String(format: "%.1f", (extraDelta as NSString).doubleValue)
+    }
+    
     if contactType == "Trend" && ObservableUserDefaults.shared.contactTrend.value == "Separate" {
         // Customizing image for Trend contact when value is Separate
         let trendRect = CGRect(x: 0, y: 46, width: size.width, height: size.height - 80)
@@ -136,7 +145,7 @@ class ContactImageUpdater {
     } else if contactType == "Delta" && ObservableUserDefaults.shared.contactDelta.value == "Separate" {
         // Customizing image for Delta contact when value is Separate
         let deltaRect = CGRect(x: 0, y: 46, width: size.width, height: size.height - 80)
-        extraDelta.draw(in: deltaRect, withAttributes: separateAttributes)
+        formattedExtraDelta.draw(in: deltaRect, withAttributes: separateAttributes)
     } else if contactType == "BG" {
         // Customizing image for BG contact
         let bgRect = extra.isEmpty