Browse Source

add gradient

marinofaggiana 5 years ago
parent
commit
532840ccaf

+ 1 - 1
iOSClient/Main/CCMain.m

@@ -3897,7 +3897,7 @@
             
         } else {
             
-            [self.viewRichWorkspace setRichWorkspaceText:directory.richWorkspace];
+            [self.viewRichWorkspace setRichWorkspaceText:directory.richWorkspace gradient:true];
             [self.viewRichWorkspace setFrame:CGRectMake(0, 0, self.tableView.frame.size.width, height)];
             [self.tableView setTableHeaderView:self.viewRichWorkspace];
         }

+ 17 - 4
iOSClient/RichWorkspace/NCRichWorkspace.swift

@@ -29,6 +29,8 @@ import SwiftRichString
     
     @IBOutlet weak var textView: UITextView!
     var richWorkspace: String = ""
+    var gradient: Bool = false
+    let gradientLayer: CAGradientLayer = CAGradientLayer()
 
     required init?(coder: NSCoder) {
         super.init(coder: coder)
@@ -39,10 +41,13 @@ import SwiftRichString
     
     @objc func changeTheming() {
         self.backgroundColor = NCBrandColor.sharedInstance.backgroundView
-        setRichWorkspaceText(richWorkspace)
+        setRichWorkspaceText(richWorkspace, gradient: gradient)
     }
     
-    @objc func setRichWorkspaceText(_ richWorkspace: String) {
+    @objc func setRichWorkspaceText(_ richWorkspace: String, gradient: Bool) {
+        
+        self.richWorkspace = richWorkspace
+        self.gradient = gradient
         
         let h1 = Style {
             $0.font = UIFont.systemFont(ofSize: 25, weight: .bold)
@@ -73,9 +78,7 @@ import SwiftRichString
             $0.color = NCBrandColor.sharedInstance.textView
         }
        
-        self.richWorkspace = richWorkspace
         var richWorkspaceStyling = ""
-        
         let richWorkspaceArray = richWorkspace.components(separatedBy: "\n")
         for string in richWorkspaceArray {
             if string.hasPrefix("# ") {
@@ -98,5 +101,15 @@ import SwiftRichString
         textView.attributedText = richWorkspaceStyling.set(style: StyleGroup(base: normal, ["h1": h1, "h2": h2, "h3": h3, "h4": h4, "h5": h5, "h6": h6]))
         textView.isUserInteractionEnabled = false
         textView.sizeToFit()
+        
+        if gradient {
+            
+            gradientLayer.removeFromSuperlayer()
+            gradientLayer.frame = CGRect(x: 0.0, y: 0.0, width: self.frame.width, height: self.frame.height)
+            gradientLayer.colors = [UIColor.init(white: 1, alpha: 0).cgColor, UIColor.white.cgColor]
+            gradientLayer.startPoint = CGPoint(x: 0, y: 0.60)
+            gradientLayer.endPoint = CGPoint(x: 0, y: 1)
+            textView.layer.addSublayer(gradientLayer)
+        }
     }
 }

+ 1 - 1
iOSClient/Viewer/NCViewerRichWorkspace.swift

@@ -40,7 +40,7 @@ import Foundation
         self.navigationItem.leftBarButtonItem = closeItem
         editItem.image = UIImage(named: "actionSheetModify")
 
-        viewRichWorkspace.setRichWorkspaceText(richWorkspace)
+        viewRichWorkspace.setRichWorkspaceText(richWorkspace, gradient: false)
         
         NotificationCenter.default.addObserver(self, selector: #selector(self.changeTheming), name: NSNotification.Name(rawValue: "changeTheming"), object: nil)
         changeTheming()