Giter Site home page Giter Site logo

Comments (4)

mchoe avatar mchoe commented on July 23, 2024

Hi @nikhilrtrivedi, You should be able to specify any local URL as that UIView initializer is a convenience initializer over the ability to load from Data. In other words, you should not have to do any special sort of formatting for the URL. It should load either local or remote URLs.

Just to check, are you ensuring that the file exists at that path? Without further information, it's hard to diagnose the problem and maybe you can provide some sample code.

from swiftsvg.

nikhil-heady avatar nikhil-heady commented on July 23, 2024

@mchoe Hi, Thank you for quick reply. If file path is wrong i get the error message that file do not exists at path. So path is correct, still it is not loading the svg image.

from swiftsvg.

nikhil-heady avatar nikhil-heady commented on July 23, 2024

@mchoe Hi, We are try to load svg into cell view. Code is as below.

import QuickLook
import PromiseKit
import Shimmer
import UIKit
import WebKit
import SwiftSVG

class KeyDocumentVC: UIViewController, UITableViewDelegate, UITableViewDataSource  {
    
    var name: String! = ""
    var pages: [GetFilesQuery.Data.FilesMessage.Page?] = []
    var shimmeringView: FBShimmeringView = FBShimmeringView()
    private var promises: [PromiseKit.Promise<URL>] = []
    //    private var promise: PromiseKit.Promise<URL>
    
    @IBOutlet weak var menuTableView: UITableView!
    @IBOutlet weak var largeTableView: UITableView!
    @IBOutlet weak var navigationBar: UINavigationBar!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        menuTableView.dataSource = self
        menuTableView.delegate = self
        
        largeTableView.dataSource = self
        largeTableView.delegate = self
    }
    
    @objc func dismissMe() {
        dismiss(animated: true)
    }
    
    struct CellItem {
        let render: (CGSize) -> UIView
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(true)
        
        self.navigationBar.shadowImage = UIImage()
        self.navigationBar.setBackgroundImage(UIImage(), for: .default)
        
        for page in pages {
            let promise:PromiseKit.Promise<URL> = API.file(id: (page?.id)!)
            print("promise url ",promise)
            promises.append(promise)
        }
        
        when(fulfilled: promises ).then {_ in
            self.refreshData()
        }
    }
    
    @IBAction func returnHome(_ sender: Any) {
        
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    internal func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    internal func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        //return 1
        return promises.count
    }
    
    internal func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        var cell = tableView.dequeueReusableCell(withIdentifier: "menuCell", for: indexPath) as? KeyDocumentTableViewCell
        if cell == nil {
            cell = KeyDocumentTableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "menuCell")
        }
        
        cell?.pageIndexLabel.text = "\(indexPath.row)"
        let svgRect = (tableView == menuTableView) ? CGRect(x: 32, y: 48, width: 257, height: 292) : CGRect(x: 97, y: 43, width: 510, height: 575)
        
        //let dst = FileManager.cache/"KeyDocuments"/"\(rq.url!.hashValue).svg"
        
        if promises[indexPath.row].isResolved {
            let pageUrl = promises[indexPath.row].value!
            let fileName = pageUrl.lastPathComponent
            let dst = FileManager.cache/"KeyDocuments"/"\(fileName)"
            if FileManager.default.fileExists(atPath: dst.path) {
                //print("FILE Yes AVAILABLE")
            } else {
                //print("FILE NOT AVAILABLE")
            }
            
            ///let fileData = NSData(contentsOfFile: NSString(dst.path))
                let thisItem = CellItem(render: { (cellSize) -> UIView in
                    print(dst,"\n") //file:///Users/nikhiltrivedi/Library/Developer/CoreSimulator/Devices/140F07EB-3AE0-46A6-A318-F2A01367B859/data/Containers/Data/Application/EC3A53EB-BD75-4C23-88A1-3D203C27AEC9/Library/Caches/KeyDocuments/4607512156414687203.svg 
                    let hammock = UIView(SVGURL: dst) { (svgLayer) in
                        svgLayer.fillColor = UIColor.red.cgColor
                        svgLayer.resizeToFit(CGRect(x: 0, y: 0, width: cellSize.width, height: cellSize.height))
                    }
                    return hammock
                })
            
           cell?.svgView.addSubview(thisItem.render(CGSize(width: svgRect.size.width, height: svgRect.size.width)))
           //cell?.svgView.backgroundColor = UIColor.red
        }
        
        return cell!
    }

    internal func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return tableView == menuTableView ? 400 : 700
    }
    
    private func refreshData() {
        self.menuTableView.reloadData()
        self.largeTableView.reloadData()
    }

    
}

            

from swiftsvg.

nikhil-heady avatar nikhil-heady commented on July 23, 2024

@mchoe Hi can you please check above updated code. What can be the issue. I have cross checked the file path it is valid one. I will appreciate if you can look into it.

from swiftsvg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.