1

我展示了我的日历选择器,如下所示:

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)

我更改了导航控制器按钮Cancel(左上)、Done(右上)和Add Calendar(左下)的颜色。事实上我不需要这个Add calendar功能。我试过导航控制器和日历选择器hidesBottomBarWhenPushed = falsetabBarItem = nil没有喜悦。

问题1:是否可以删除Add calendar按钮?

如果我无法删除Add Calendar按钮,我至少希望将其Cancel按钮(左上角)的颜色也更改为橙色(它显示默认蓝色)。

问题 2:如何更改控制器Cancel上显示的按钮颜色Add calendar

4

1 回答 1

1

我认为没有任何公共 API 可以删除“添加日历”按钮。

按钮的色调由应用程序的全局色调控制。但是,在情节提要中设置全局色调只会影响情节提要上的视图。故事板所称的“全局”色调实际上并不是全局色调。

从 iOS 14 开始,您可以在目标的构建设置中搜索“全局强调色”,将其设置为一个名称,然后在 Asset Catalog 中使用该名称创建一个颜色集。然后该颜色将成为您应用的全局色调颜色。例子:

在此处输入图像描述

在此处输入图像描述

如果您的项目是使用相当新版本的 Xcode 创建的,则应该已经为您设置了此设置,并且资产目录中应该已经设置了一个名为“AccentColor”的颜色。

在 iOS 14 之前,您将设置window.tintColor. 请参阅此问题的答案。

在那之后,你甚至不需要这一行:

navigationController.view.tintColor = .orange
于 2021-08-13T08:31:52.960 回答