swifteventkitekcalendar

Remove Add Calendar button from Calendar Chooser


I present my Calendar Chooser as shown below:

let calendarChooser = EKCalendarChooser(selectionStyle: .single,
                                        displayStyle: .writableCalendarsOnly,
                                        entityType: .event,
                                        eventStore: eventStore)
calendarChooser.showsDoneButton = true
calendarChooser.showsCancelButton = true
let navigationController = UINavigationController(rootViewController: calendarChooser)
navigationController.view.tintColor = .orange // change color of navigation controller buttons
self.present(navigationController, animated: true, completion: nil)

I change the color of the navigation controller buttons Cancel (top left), Done (top right) and Add Calendar (bottom left). In fact I do not need the Add calendar feature. I tried hidesBottomBarWhenPushed = false and tabBarItem = nil on navigation controller and calendar chooser. No joy.

Question 1: Is it possible to remove the Add calendar button?

If I cannot remove Add Calendar button, I would like at least to change the color of its Cancel button (top left) to orange as well (it shows default blue).

Question 2: How can I change the color of the Cancel button shown on Add calendar controller?


Solution

  • I don't think there is any public API to remove the "Add Calendar" button.

    The tint color of the buttons are controlled by the global tint of your app. However, setting the global tint in the storyboard only affects views on the storyboard. What the storyboard calls the "global" tint isn't actually the global tint.

    Since iOS 14, you can search for "global accent color" in the build settings of your target, set it to a name, then create a color set in the Asset Catalog with that name. That color will then become your app's global tint color. Example:

    enter image description here

    enter image description here

    If your project was created using a rather new version of Xcode, this setting should have already been set for you, and there should already been a color set in the asset catalog called "AccentColor".

    Before iOS 14, you would set window.tintColor. See the answers to this.

    After that, you don't even need this line:

    navigationController.view.tintColor = .orange