marinofaggiana 4 lat temu
rodzic
commit
9cceec312b

+ 5 - 5
iOSClient/Main/NCMainTabBar.swift

@@ -139,14 +139,14 @@ class NCMainTabBar: UITabBar {
         // File
         if let item = items?[0] {
             item.title = NSLocalizedString("_home_", comment: "")
-            item.image = CCGraphics.changeThemingColorImage(UIImage(named: "tabBarFiles"), width: 50, height: 50, color: NCBrandColor.shared.brandElement)
+            item.image = UIImage(named: "tabBarFiles")?.image(color: NCBrandColor.shared.brandElement, size: CGSize(width: 25, height: 25))
             item.selectedImage = item.image
         }
         
         // Favorite
         if let item = items?[1] {
             item.title = NSLocalizedString("_favorites_", comment: "")
-            item.image = CCGraphics.changeThemingColorImage(UIImage(named: "favorite"), width: 50, height: 50, color: NCBrandColor.shared.brandElement)
+            item.image = UIImage(named: "favorite")?.image(color: NCBrandColor.shared.brandElement, size: CGSize(width: 25, height: 25))
             item.selectedImage = item.image
         }
         
@@ -160,14 +160,14 @@ class NCMainTabBar: UITabBar {
         // Media
         if let item = items?[3] {
             item.title = NSLocalizedString("_media_", comment: "")
-            item.image = CCGraphics.changeThemingColorImage(UIImage(named: "media"), width: 50, height: 50, color: NCBrandColor.shared.brandElement)
+            item.image = UIImage(named: "media")?.image(color: NCBrandColor.shared.brandElement, size: CGSize(width: 25, height: 25))
             item.selectedImage = item.image
         }
         
         // More
         if let item = items?[4] {
             item.title = NSLocalizedString("_more_", comment: "")
-            item.image = CCGraphics.changeThemingColorImage(UIImage(named: "tabBarMore"), width: 50, height: 50, color: NCBrandColor.shared.brandElement)
+            item.image = UIImage(named: "tabBarMore")?.image(color: NCBrandColor.shared.brandElement, size: CGSize(width: 25, height: 25))
             item.selectedImage = item.image
         }
         
@@ -182,7 +182,7 @@ class NCMainTabBar: UITabBar {
         let centerButton = UIButton(frame: CGRect(x: (self.bounds.width / 2)-(centerButtonHeight/2), y: centerButtonY, width: centerButtonHeight, height: centerButtonHeight))
         
         centerButton.setTitle("", for: .normal)
-        centerButton.setImage(CCGraphics.changeThemingColorImage(UIImage(named: "tabBarPlus"), width: 100, height: 100, color: .white), for: .normal)
+        centerButton.setImage(UIImage(named: "tabBarPlus")?.image(color: .white, size: CGSize(width: 100, height: 100)), for: .normal)
         centerButton.backgroundColor = NCBrandColor.shared.brandElement
         centerButton.tintColor = UIColor.white
         centerButton.tag = 99

+ 0 - 35
iOSClient/Utility/CCGraphics.m

@@ -179,41 +179,6 @@
     return [UIImage imageWithCGImage:img.CGImage scale:UIScreen.mainScreen.scale orientation: UIImageOrientationDownMirrored];
 }
 
-+ (UIImage *)grayscale:(UIImage *)sourceImage
-{
-    /* const UInt8 luminance = (red * 0.2126) + (green * 0.7152) + (blue * 0.0722); // Good luminance value */
-    /// Create a gray bitmap context
-    const size_t width = (size_t)sourceImage.size.width;
-    const size_t height = (size_t)sourceImage.size.height;
-    
-    const int kNyxNumberOfComponentsPerGreyPixel = 3;
-    
-    CGRect imageRect = CGRectMake(0, 0, sourceImage.size.width, sourceImage.size.height);
-    
-    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
-    CGContextRef bmContext = CGBitmapContextCreate(NULL, width, height, 8/*Bits per component*/, width * kNyxNumberOfComponentsPerGreyPixel, colorSpace, kCGImageAlphaNone);
-    CGColorSpaceRelease(colorSpace);
-    if (!bmContext)
-        return nil;
-    
-    /// Image quality
-    CGContextSetShouldAntialias(bmContext, false);
-    CGContextSetInterpolationQuality(bmContext, kCGInterpolationHigh);
-    
-    /// Draw the image in the bitmap context
-    CGContextDrawImage(bmContext, imageRect, sourceImage.CGImage);
-    
-    /// Create an image object from the context
-    CGImageRef grayscaledImageRef = CGBitmapContextCreateImage(bmContext);
-    UIImage *grayscaled = [UIImage imageWithCGImage:grayscaledImageRef scale:sourceImage.scale orientation:sourceImage.imageOrientation];
-    
-    /// Cleanup
-    CGImageRelease(grayscaledImageRef);
-    CGContextRelease(bmContext);
-    
-    return grayscaled;
-}
-
 + (void)settingThemingColor:(NSString *)themingColor themingColorElement:(NSString *)themingColorElement themingColorText:(NSString *)themingColorText
 {
     UIColor *newColor, *newColorElement, *newColorText;

+ 21 - 0
iOSClient/Utility/UIImage+Extensions.swift

@@ -119,4 +119,25 @@ extension UIImage {
         guard let newCGImage = ctx.makeImage() else { return nil }
         return UIImage.init(cgImage: newCGImage, scale: 1, orientation: .up)
     }
+    
+    @objc func image(color: UIColor, size: CGSize) -> UIImage {
+        
+        UIGraphicsBeginImageContextWithOptions(size, false, self.scale)
+        color.setFill()
+
+        let context = UIGraphicsGetCurrentContext()
+        context?.translateBy(x: 0, y: size.height)
+        context?.scaleBy(x: 1.0, y: -1.0)
+        context?.setBlendMode(CGBlendMode.normal)
+
+        let rect = CGRect(origin: .zero, size: CGSize(width: size.width, height: size.height))
+        guard let cgImage = self.cgImage else { return self }
+        context?.clip(to: rect, mask: cgImage)
+        context?.fill(rect)
+
+        let newImage = UIGraphicsGetImageFromCurrentImageContext() ?? self
+        UIGraphicsEndImageContext()
+        
+        return newImage
+    }
 }