Search code examples
swiftswiftuicolorsswift3uiactivityviewcontroller

Change UIActivityViewController Subview Background colour SwiftUI


I'm trying to change UIActivityViewController subview background colour means when UIActivityViewController open and then user click on reminder the reminder background colour automatically change. i want to set same as from theme according.

Code:-

struct ShareSheet: UIViewControllerRepresentable {
typealias Callback = (_ activityType: UIActivity.ActivityType?, _ completed: Bool, _ returnedItems: [Any]?, _ error: Error?) -> Void
  
let activityItems: [Any]
var callback: Callback

let applicationActivities: [UIActivity]? = nil
let excludedActivityTypes: [UIActivity.ActivityType]? = [.addToReadingList]
    
func makeUIViewController(context: Context) -> UIActivityViewController {
    let controller = UIActivityViewController(
        activityItems: activityItems,
        applicationActivities: applicationActivities)
    controller.excludedActivityTypes = excludedActivityTypes
    controller.completionWithItemsHandler = callback
    controller.navigationController?.navigationBar.tintColor = .lightGray
    controller.view.tintColor = .lightGray
    controller.overrideUserInterfaceStyle = .light
    return controller
}
  
func updateUIViewController(_ uiViewController: UIActivityViewController, context: Context) {
}

init(activityItems: [Any], callback: @escaping Callback = { activityType, completed, returnedItems, error in }) {
    self.activityItems = activityItems
    self.callback = callback
    }
}

Output:-

First Screen:-

ScreenShot

Second Screen:-

ScreenShot

Third Screen:-

ScreenShot

Expected Output:-

First Screen:-

Screen Shot

Second Screen:-

Screen Shot

Question: How to change background colour according to theme? I've tried to with above code but no results yet.

Can someone please explain to me How to get Progress?

Any help would be greatly appreciated.

Thanks in advance.


Solution

  • I have added Tableview background in other class. So i need to Update The Tableview Cell Colour in the Init.

    Code:-

    init(activityItems: [Any], callback: @escaping Callback = { activityType, completed, returnedItems, error in }) {
            self.activityItems = activityItems
            self.callback = callback
            UITableView.appearance().backgroundColor = UIColor.systemGroupedBackground
            UITableViewCell.appearance().backgroundColor = UIColor.systemGroupedBackground
    }