Forum Archive

Making a Transparent Webview

zmous

so kinda wanted to create animated charts in pythonista except that matplotlib creates static ones and non interactive charts. I was thinking if there's a way to sorta wrap Chartjs (a JavaScript library for cretaing charts) in a webview and set it's background to be clear. i tried doing this but i ran into a problem:
• setting a clear background webview doesn't seem all that easy, although it seems that it could be done using obj_util (something i am unfamiliar with)

Any help would be very much appreciated thanks alot

Update: All right so i have been looking around and found this: https://stackoverflow.com/questions/3646930/how-to-make-a-transparent-uiwebview

Which i tried implementing as follows ( But for some reason pythonista crashes instead):

#[webView setBackgroundColor:[UIColor clearColor]];

from objc_util import *
import ui

UIColor=ObjCClass('UIColor')

class WebViewContainer (ui.View):
    def __init__(self, web_view):
        ui.View.__init__(self)
        self.web_view = web_view
        self.add_subview(web_view)
        _web_view = ObjCInstance(web_view)
        _web_view.setBackgroundColor_(UIColor.clearColor().CGColor())
        _web_view.setOpaque_('NO')

w,h=ui.get_screen_size()
wv=ui.WebView()
wv.frame=(0,0,w,h)
wvo=WebViewContainer(wv)
view=ui.View()
view.add_subview(wvo)
view.present()
cvp

@zmous Please, Try this code

cvp

@zmous only one change needed:

        _web_view.setBackgroundColor_(UIColor.clearColor())#.CGColor())
zmous

@cvp unfortunately crashes, however the code provided by @zrzka does work just fine. Anyway thanks alot!

cvp

@zmous Strange, your code with only the little modification above commented the .CGColor() does not crash for me