0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

SwiftUIでSafariを表示させる

Posted at

はじめに

今回はSwiftUIを使ってSafariを表示するための画面を実装していきます

コード

実装は下記になります
呼び出す側はSsafariView(URL)のようにすればどの画面でも表示することができます

import SwiftUI
import SafariServices

struct SafariView: UIViewControllerRepresentable {
    let url: URL

    func makeUIViewController(context: Context) -> SFSafariViewController {
        let safariVC = SFSafariViewController(url: url)
        safariVC.preferredControlTintColor = .blue
        safariVC.dismissButtonStyle = .close
        return safariVC
    }

    func updateUIViewController(_ uiViewController: SFSafariViewController, context: Context) { }
}

さいごに

JetpackComposeではComponentがでましたが、Swiftは自前なので今回は記事を書いてみました
IOSは公式からくるんですかね

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?