swift 自定义RPPreviewViewController(ReplayKit)中按钮的颜色

ykejflvf  于 2023-04-04  发布在  Swift
关注(0)|答案(2)|浏览(162)

我用RPCreenRecorder录制了一段视频。一切都很好。

现在我想自定义预览控制器的UI,如何更改取消和保存按钮的颜色?嗯,一般我知道如何更改UIBarButtonItem的颜色:

let cancelBtn = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(self.dismissView))
cancelBtn.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.red], for: .normal)

但是我在预览中找不到按钮的引用(RPPreviewViewController)。

func stopRecorder() {
        recorder.stopRecording { [unowned self] (preview, error) in            
            guard let previewVC = preview else {
                return
            }
            previewVC.previewControllerDelegate = self
            previewVC.modalPresentationStyle = .fullScreen
            self.present(previewVC, animated: true, completion: nil)
        }
    }
``
0vvn1miw

0vvn1miw1#

在呈现/推送视图控制器时尝试以下代码

UINavigationBar.appearance().barTintColor = Colors.redColor()
UINavigationBar.appearance().tintColor = UIColor.white
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor.white, NSFontAttributeName: UIFont.systemFont(ofSize: 14, weight: UIFontWeightBold)]

请注意:不要忘记在关闭/弹出视图控制器时重置所有这些值,因为所有这些值都适用于整个应用程序的所有导航控制器。

laximzn5

laximzn52#

如果你在SwiftUI中使用RPPreviewViewController,我可以使用accentColor更改预览控制器导航栏中按钮的颜色。

if isShowPreviewVideo {
    replayKitPreview
      .transition(.move(edge: .bottom))
      .accentColor(Color(hex: 0x0096FF))
      .edgesIgnoringSafeArea(.all)
}

相关问题