小编Gre*_*ams的帖子

WKWebView在safari中打开来自某个域的链接

寻求我的iOS应用程序的一些帮助.在我的应用程序中,我想在WKWebView中打开我的域内的点击链接(EX:communionchapelefca.org),然后在Safari中打开所有其他域(EX:google.com)的链接.我更喜欢以程序方式执行此操作,因为这是我的代码已经设置的方式.

我在stackoverflow上找到了一些解决方案(这里,这里,这里,这里),但它们似乎都是基于Obj-C的,我正在寻找使用Swift的解决方案.提前致谢.

ViewController.swift:

import UIKit
import WebKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let myWebView:WKWebView = WKWebView(frame: CGRectMake(0, 0,   UIScreen.mainScreen().bounds.width, UIScreen.mainScreen().bounds.height))

        myWebView.loadRequest(NSURLRequest(URL: NSURL(string: "http://www.communionchapelefca.org/app-home")!))

        self.view.addSubview(myWebView)
Run Code Online (Sandbox Code Playgroud)

safari ios swift wkwebview

35
推荐指数
4
解决办法
3万
查看次数

iOS - 如何以编程方式创建WKWebView Back Button?

我正在尝试为我的iOS WKWebView应用程序创建一个后退按钮,这样当用户点击按钮时它会将它们带到之前的WKWebView页面.我已经找到了很多关于如何使用IB而不是直接代码的教程.这是我到目前为止:

原始ViewController.swift:

import UIKit
import WebKit

class ViewController: UIViewController, WKNavigationDelegate {

    private var webView: WKWebView!

    let wv = WKWebView(frame: UIScreen.mainScreen().bounds) //needed for working webview

    self.webView = WKWebView(frame: frame)
    self.webView.navigationDelegate = self

    func rightbutton(text: String, action: Selector) {
        let rightButton = UIBarButtonItem(title: text, style: .Plain, target: self, action: action)
        self.navigationItem.rightBarButtonItem = rightButton
    }

    func action() {
        if self.webView.canGoBack {
            print ("Can go back")
            self.webView.goBack()
            self.webView.reload()

        } else {
            print ( "Can't go back")
        }
    }


    override func viewDidLoad() {
        super.viewDidLoad() …
Run Code Online (Sandbox Code Playgroud)

uibutton ios wkwebview

8
推荐指数
1
解决办法
1万
查看次数

将UIWebView迁移到WKWebView

在我的iOS应用程序中,我尝试将旧的UIWebView代码迁移到WKWebView,因为从理论上讲,WKWebView比UIWebView更快,更高效。

我在互联网上看了一堆教程(如此此处此处),但是找不到任何解释如何简单地将WKWebView编程添加到我的应用程序的内容。

有人可以给我指出一个简单的教程,也可以在注释中解释如何通过编程将代码转换为WKWebView吗?提前致谢。

查看Controller.swift:

import UIKit

class ViewController: UIViewController, UIWebViewDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

        let myWebView:UIWebView = UIWebView(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, UIScreen.mainScreen().bounds.height))

        myWebView.loadRequest(NSURLRequest(URL: NSURL(string: "http://www.communionchapelefca.org/app-home")!))
        self.view.addSubview(myWebView)
Run Code Online (Sandbox Code Playgroud)

uiwebview ios swift wkwebview

4
推荐指数
1
解决办法
5969
查看次数

Android Studio - 白色横跨顶部的酒吧

所以我只是构建了一个应用程序,但顶部是一个白色条形图.我相信它的ActionBar,但每次改变颜色的尝试都不起作用.有关如何删除它或改变颜色的任何想法?谢谢.在此输入图像描述

Activity.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <WebView
        android:id="@+id/activity_main_webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <ProgressBar
        android:layout_centerHorizontal="true"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_centerVertical="true"
        android:layout_centerInParent="true"
        android:id="@+id/progressBar1"
        style="@android:style/Widget.ProgressBar.Small.Inverse" />

    <TextView
        android:layout_centerHorizontal="true"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_centerVertical="true"
        android:layout_centerInParent="true"
        android:id="@+id/LoadingText"
        android:layout_below="@+id/progressBar1"
        android:text="@string/loading_txt"
        android:textSize="20sp"/>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:clickable="true"
        android:src="@android:drawable/ic_menu_edit"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        app:fabSize="normal"
        app:layout_anchorGravity="bottom|right|end"
        app:backgroundTint="#243313"
        app:rippleColor="#FFF" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

styles.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" …
Run Code Online (Sandbox Code Playgroud)

xml android webview android-actionbar

3
推荐指数
1
解决办法
2011
查看次数