簡體   English   中英

如何更改 SFSafariViewController 工具欄顏色

[英]How to change SFSafariViewController ToolBar color

預期輸出:我想將工具欄顏色更改為深黑色。

實際輸出:工具欄為淺灰色。

這是代碼:

let webViewController = SFSafariViewController(URL: url, entersReaderIfAvailable: true)
self.navigationController?.toolbar.barTintColor = UIColor.blackColor()
self.navigationController?.toolbar.tintColor = UIColor.whiteColor()
self.navigationController?.toolbar.barStyle = UIBarStyle.Black
self.navigationController?.pushViewController(webViewController, animated: true)

iOS 10 API 的更新答案

SFSafariViewController現在具有preferredBarTintColorpreferredControlTintColor屬性來控制工具欄的外觀。


原答案

SFSafariViewController在進程SFSafariViewController渲染。 您只能更改色調顏色,而不能更改條形樣式或條形色調顏色。

要設置色調顏色,請像這樣設置 Safari 控制器視圖的色調顏色:

let sfController = SFSafariViewController(URL: url, entersReaderIfAvailable: true)
sfController.view.tintColor = UIColor.redColor()
navigationController?.showViewController(sfController, sender: self)

有兩種方式:

let resetPasswordSafari = SFSafariViewController(url: url, entersReaderIfAvailable: true)
resetPasswordSafari.preferredBarTintColor = .mainColor
resetPasswordSafari.preferredControlTintColor = .black

和:

class ResetPasswordSafariViewController: SFSafariViewController {

  override init(url URL: URL, entersReaderIfAvailable: Bool) {
    super.init(url: URL, entersReaderIfAvailable: entersReaderIfAvailable)
    delegate = self

    preferredBarTintColor = .blue
    preferredControlTintColor = .black
  }
}

// MARK: - SFSafariViewControllerDelegate

extension ResetPasswordSafariViewController: SFSafariViewControllerDelegate {
  internal func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
    controller.dismiss(animated: true)
  }
}

祝大家好運!

我認為無法更改 ToolBar 的背景顏色,但可以更改 ToolBar 中按鈕的顏色。

[UIBarButtonItem appearance].tintColor = [UIColor whiteColor];

正如我所見,所有其他外觀變化或直接在控制器屬性中的變化都沒有影響。

//在SFSafariViewController中進行更改

     if let url = URL(string:"https://sandydhumale.business.site") {
        let config = SFSafariViewController.Configuration()
        config.entersReaderIfAvailable = true
        config.barCollapsingEnabled = true
        let vc = SFSafariViewController(url: url, configuration: config)
        vc.dismissButtonStyle = .close
        vc.preferredBarTintColor = .green // Your choice color
        vc.preferredControlTintColor = .white // All buttons/items color
        self.present(vc, animated: true, completion: nil)
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM