marinofaggiana 3 years ago
parent
commit
efe4bdaa53

+ 26 - 1
iOSClient/Security/NCViewCertificateDetails.swift

@@ -53,7 +53,32 @@ class NCViewCertificateDetails: UIViewController  {
         if FileManager.default.fileExists(atPath: certificatePath) {
             do {
                 let text = try String(contentsOfFile: certificatePath, encoding: .utf8)
-                CCUtility.viewText(self.view, scrollView: scrollView, contentText: text)
+                let font = UIFont.systemFont(ofSize: 13)
+                let attributes = [NSAttributedString.Key.font: font] as [NSAttributedString.Key : Any]
+                var contentRect = NSString(string: text).boundingRect(with: CGSize(width: CGFloat.greatestFiniteMagnitude, height: 0), options: NSStringDrawingOptions.usesLineFragmentOrigin, attributes: attributes, context: nil)
+                contentRect = CGRect(x: contentRect.origin.x, y: contentRect.origin.y, width: ceil(contentRect.size.width), height: ceil(contentRect.size.height))
+                var contentWidth = contentRect.size.width
+                if contentWidth < view.frame.size.width {
+                    contentWidth = view.frame.size.width
+                }
+                var contentHeight = contentRect.size.height
+                if contentHeight < view.frame.size.height {
+                    contentHeight = view.frame.size.width
+                }
+                let textViewFrame = CGRect(x: 0, y: 0, width: contentWidth, height: contentHeight)
+                
+                let textView = UITextView.init(frame: textViewFrame)
+                textView.translatesAutoresizingMaskIntoConstraints = false
+                textView.isEditable = false
+                textView.isScrollEnabled = true
+                textView.font = font
+                textView.text = text
+                textView.sizeToFit()
+                
+                scrollView.addSubview(textView)
+                scrollView.contentSize = contentRect.size
+                scrollView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 40, right: -40)
+                
             } catch {
                 print("error")
             }

+ 0 - 1
iOSClient/Utility/CCUtility.h

@@ -264,6 +264,5 @@
 + (NSString *)getExtension:(NSString*)fileName;
 + (NSDate *)datetimeWithOutTime:(NSDate *)datDate;
 + (NSString *)valueForKey:(NSString *)key fromQueryItems:(NSArray *)queryItems;
-+ (void)viewText:(UIView *)view scrollView:(UIScrollView *)scrollView contentText:(NSString *)contentText;
 
 @end

+ 0 - 47
iOSClient/Utility/CCUtility.m

@@ -1821,51 +1821,4 @@
     return queryItem.value;
 }
 
-+ (void)viewText:(UIView *)view scrollView:(UIScrollView *)scrollView contentText:(NSString *)contentText
-{
-    UIFont *font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
-    NSDictionary *attributes = @{ NSFontAttributeName: font };
-
-    // Load text and detect size
-    CGRect contentRect = [contentText boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 0) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:attributes context:nil];
-    // Fix up values
-    contentRect = CGRectMake(contentRect.origin.x, contentRect.origin.y, ceil(contentRect.size.width), ceil(contentRect.size.height));
-
-    CGSize contentSize = contentRect.size;
-    CGFloat contentWidth = contentRect.size.width;
-    if (contentWidth < view.frame.size.width) {
-        // text view minimum frame width is the width of the root view frame
-        contentWidth = view.frame.size.width;
-    }
-    CGFloat contentHeight = contentRect.size.height;
-    if (contentHeight < view.frame.size.height) {
-        // text view minimum frame width is the width of the root view frame
-        contentHeight = view.frame.size.width;
-    }
-
-    // TextView frame
-    CGRect textViewFrame = CGRectMake(0, 0, contentWidth, contentHeight);
-    NSLog(@"textViewFrame: %@", NSStringFromCGRect(textViewFrame));
-
-    UITextView *textView = [[UITextView alloc] initWithFrame:textViewFrame];
-    textView.translatesAutoresizingMaskIntoConstraints = NO;
-    textView.editable = NO;
-    textView.scrollEnabled = YES; // When this is NO nothing shows up
-
-    // TextView border for debugging
-    //textView.layer.borderWidth = 1;
-    //textView.layer.borderColor = [UIColor redColor].CGColor;
-
-    // Text Style
-    textView.font = font;
-
-    // Load text into textView
-    textView.text = contentText;
-    [textView sizeToFit];
-
-    [scrollView addSubview:textView];
-
-    scrollView.contentSize = contentSize; // scrollSize;
-    scrollView.contentInset = UIEdgeInsetsMake(0, 0, 40, -40);
-}
 @end