1

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?

geohei
  • 696
  • 4
  • 15
  • I don't think there is any public APIs to remove "Add Calendar". The color of the cancel button is set to your app's global tint. It seems like you haven't actually set your app's global tint yet, which is why it is blue. Is your app's global tint also orange? If so, I can show you how to set the global tint. – Sweeper Aug 13 '21 at 08:02
  • Besides, what is the point of removing "Add Calendar"? The user can always just add another calendar in the Calendar app, so removing it doesn't actually prevent anything, and just inconveniences the user. Right? – Sweeper Aug 13 '21 at 08:04
  • Removing ``Add calendar`` was more a cosmetic wish. I know it can always be added somewhere else, but since I didn't manage to change the color of the ``Cancel``button in it, I tried to remove it completely. - I do have the Global Tint color set to orange in storyboard. Nevertheless the ``Add Calendar`` controller shows default blue. – geohei Aug 13 '21 at 08:11
  • @Sweeper - the use case would be: user is picking only existing calendar, for example: copy/view data. (Creating new/empty calendar would be extraneous). – benc Apr 06 '23 at 07:10

1 Answers1

2

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
Sweeper
  • 213,210
  • 22
  • 193
  • 313
  • Thanks a lot. Great explanation. Answer accepted. I didn't know about AccentColor (my app was generated back 2019). AccentColor changes the Calendar Chooser and the Add Calendar button color, but not an UIAlertController. Therefore I still need ``window?.tintColor`` in AppDelegate, but this seems to be a bug since pressing and holding an action button shows the set AccentColor. Thanks also for the Global Tint explanation in storyboard - I was expecting something like that. So ... using both, AccentColor and ``window?.tintColor``, I managed to get rid of virtually all ``.tintColor`` code lines. – geohei Aug 13 '21 at 09:44