Search code examples
iosxcodeuiwebviewswift2string-concatenation

concatenate swift variables in html embedded string


Title is not very clear i know let me explain. I am displaying some vimeo videos on an UIWebView. Now i am using this bit of code to make things work:

    let embedHTML="<html><head><style type=\"text/css\">body {background-color: transparent;color: white;}</style></
    head><body style=\"margin:0\"><iframe src=\"//player.vimeo.com/video/171151492?autoplay=1&amp;loop=1\"
    width=\"266\"height=\"105\" frameborder=\"0\" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>";

Now where it says: width=\"266\"height=\"105\" i want to put in:

self.webView.frame.width

instead of 266 and

self.webView.frame.height

instead of 105

HOW can i do this? I mean i know how to concatenate strings using + but this was way to hard it did not work. Anybody got any ideas?


Solution

  • let oneVar = self.webView.frame.width
    let anotherVar = self.webView.frame.height
    

    And then:

    let embedHTML = "<html><head><style type=\"text/css\">body {background-color: transparent;color: white;}</style></
        head><body style=\"margin:0\"><iframe src=\"//player.vimeo.com/video/171151492?autoplay=1&amp;loop=1\"
        width=\"\(oneVar)\"height=\"\(anotherVar)\" frameborder=\"0\" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>";