How to import css file in UIWebView when I am using loadHTMLString() method in swift (iOS) -


i have common css file , dynamic html text. trying load css file disk , use dynamic html text display in uiwebview instead of putting same css text on , on again html text.

i trying way.

var sometext = "<html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\"></head>" + "<body><p>some text goes here</p></body></html>" let mainbundle = nsbundle.mainbundle().bundlepath let bundleurl = nsurl(fileurlwithpath: mainbundle) self.webview.loadhtmlstring(sometext, baseurl: bundleurl) 

now problem css not getting applied html. there 1 out there can help, think stuck.

please help. thanks!

i had same problem. code same russell posted.

adding css file project not enough. had reference file in "copy bundle resources" list in build phase settings.

how reference file in xcode 7:

  1. select build phase tab
  2. scroll down "copy bundle resources" section , add file. (note: if *.css files don't appear in list. click "add other" button)
  3. in options window choose "create folder reference"

thats it. worked me.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -