marinofaggiana 5 years ago
parent
commit
a10536c27a

+ 7 - 1
iOSClient/Main/NCDetailViewController.swift

@@ -116,7 +116,13 @@ class NCDetailViewController: UIViewController {
                         
         progressView.frame = CGRect(x: 0, y: navigationController.navigationBar.frame.height-progressHeight, width: navigationController.navigationBar.frame.width, height: progressHeight)
         progressView.setProgress(0, animated: false)
-        progressView.tintColor = NCBrandColor.sharedInstance.icon
+        
+        if NCBrandColor.sharedInstance.brand.isLight() {
+            progressView.tintColor = NCBrandColor.sharedInstance.brand.darker(by: 10)
+        } else {
+            progressView.tintColor = NCBrandColor.sharedInstance.brand.lighter(by: 20)
+        }
+        
         progressView.trackTintColor = .clear
         progressView.transform = CGAffineTransform(scaleX: 1, y: progressHeight)
         

+ 13 - 0
iOSClient/Utility/UIColor+adjust.swift

@@ -41,4 +41,17 @@ extension UIColor {
         let brightness = ((components[0] * 299) + (components[1] * 587) + (components[2] * 114)) / 1000
         return (brightness < 0.05)
     }
+    
+    func isLight(threshold: Float = 0.7) -> Bool {
+        let originalCGColor = self.cgColor
+
+        // Now we need to convert it to the RGB colorspace. UIColor.white / UIColor.black are greyscale and not RGB.
+        // If you don't do this then you will crash when accessing components index 2 below when evaluating greyscale colors.
+        let RGBCGColor = originalCGColor.converted(to: CGColorSpaceCreateDeviceRGB(), intent: .defaultIntent, options: nil)
+        guard let components = RGBCGColor?.components else { return false }
+        guard components.count >= 3 else { return false }
+
+        let brightness = Float(((components[0] * 299) + (components[1] * 587) + (components[2] * 114)) / 1000)
+        return (brightness > threshold)
+    }
 }