ios - WKWebView add as a subview -
from ios 8.0+, supposed use wkwebview
, in official apple documentation, add setting view wkwebview. need add subview, numerous reasons.
- i have add buttons/labels above
wkwebview
. - i can add adding
uiview
storyboard , setting codewkwebview
, looks neater adding code.
my code:
@iboutlet weak var container: uiview! private var wkwebview: wkwebview! override func loadview() { let webconfig = wkwebviewconfiguration() wkwebview = wkwebview(frame: .zero, configuration: webconfig) wkwebview.uidelegate = self } override func viewdidload() { super.viewdidload() container = wkwebview let url = url(string: "https://google.com") let request = urlrequest(url: url!) wkwebview.load(request) }
i have tried this: wkwebview add subview
i have tried container.addsubview
method, crashed nil pointer.
every time load app, there's black screen.
any ideas?
you should add instance of wkwebview
subview given view:
view.addsubview(wkwebview)
you can set frame, add constraints etc., uiview
.
Comments
Post a Comment