哪些UIKit对象控制“查找”弹出窗口的外观?

时间:2018-11-11 17:20:20

标签: ios swift user-interface themes

在我们的应用中,我们有浅色模式和深色模式,可切换文本颜色和背景颜色。 scraped_data = [] for x, row in postcodes_for_urls.iterrows(): page = requests.get("http://myurl"+(row['postcode_URL'])) soup = BeautifulSoup(page.content, 'html.parser') table = soup.find('table') if table is not None and len(table.find_all('tr'))>0: table_rows = table.find_all('tr') for tr in table_rows: td = tr.find_all('td') row = [tr.text for tr in td] scraped_data.append(row) else: scraped_data.append('EMPTY') pd.DataFrame(scraped_data, columns=["A", "B", "C"]) 是一个Theme,包含案例enumlight。我们提供了切换颜色的方法,例如:

dark

我们有一个var textColor: UIColor { switch self { case .light: return UIColor(red:60/255.0, green:60/255.0, blue:60/255.0, alpha: 1.0) case .dark: return UIColor(red: 240.0/255.0, green: 248.0/255.0, blue: 255.0/255.0, alpha: 1.0) } } 方法,将主题应用于我们在应用中使用的所有视图:

apply

当一个人在我们的应用中选择文本并按下弹出菜单项中的“查找”按钮时,出现的弹出窗口看起来正确。但是,当您单击某些视图(例如词典和siri知识)时,背景或文本颜色似乎已更改。示例:

Darkened Text

我们如何控制此弹出窗口上的文本颜色?

编辑:目标是找到按下UIMenuItems时创建的UI对象的名称。它不在XCode Debugger检查器中,也不在func apply(){ defaults.set(rawValue, forKey: "selectedTheme") UIApplication.shared.delegate?.window??.tintColor = tintColor let navBarAppearance = UINavigationBar.appearance() navBarAppearance.barStyle = barStyle navBarAppearance.backgroundColor = backgroundColor navBarAppearance.barTintColor = backgroundColor navBarAppearance.tintColor = tintColor navBarAppearance.isTranslucent = false navBarAppearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: textColor] let tabBarAppearance = UITabBar.appearance() tabBarAppearance.barStyle = barStyle tabBarAppearance.backgroundColor = backgroundColor tabBarAppearance.barTintColor = backgroundColor let toolBar = UIToolbar.appearance() toolBar.backgroundColor = backgroundColor toolBar.tintColor = backgroundColor toolBar.barStyle = barStyle toolBar.isTranslucent = false toolBar.barTintColor = backgroundColor UITableViewCell.appearance().backgroundColor = backgroundColor UILabel.appearance(whenContainedInInstancesOf: [UITableViewCell.self]).textColor = textColor UILabel.appearance().textColor = textColor UITextField.appearance().keyboardAppearance = keyboardColor UITextField.appearance().textColor = textColor UITextField.appearance().backgroundColor = backgroundColor UITextView.appearance().textColor = textColor UITextView.appearance().backgroundColor = backgroundColor MultiSelectSegmentedControl.appearance().tintColor = tintColor MultiSelectSegmentedControl.appearance().backgroundColor = backgroundColor UISegmentedControl.appearance().tintColor = tintColor UISegmentedControl.appearance().backgroundColor = backgroundColor UIButton.appearance().tintColor = tintColor BigButton.appearance().backgroundColor = Theme.current.tintColor BigButton.appearance().tintColor = Theme.current.backgroundColor UIPickerView.appearance().backgroundColor = Theme.current.backgroundColor UIPickerView.appearance().tintColor = Theme.current.tintColor UITableView.appearance().backgroundColor = backgroundColor UITableView.appearance().separatorColor = cellSelectionColor UISearchBar.appearance().backgroundColor = backgroundColor UISearchBar.appearance().barTintColor = tintColor UISearchBar.appearance().searchBarStyle = .minimal UITextView.appearance().backgroundColor = backgroundColor UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).textColor = textColor UISwitch.appearance().onTintColor = tintColor let colorView = UIView() colorView.backgroundColor = cellSelectionColor UITableViewCell.appearance().selectedBackgroundView = colorView } 中。似乎是某种内置对象,对其余的过程都是隐藏的。

1 个答案:

答案 0 :(得分:1)

可能存在一两个问题

1) 您需要确保没有在代码中显式设置标签的textColorbackgroundColor的{​​{1}}。 view的{​​{1}}应该保留Label,以便它可以使用color default。例如,假设我们已将appearance设置为默认值,如下图所示,

enter image description here

现在,如果我们通过执行colortextColor上应用textColor外观。打开弹出窗口后,它将UILabel更改为UILabel.appearance().textColor = .green

但是,如果您在按如下所示设置外观后要显式设置textColor,

color

然后它将放弃green设置并设置您稍后提供的UILabel.appearance().textColor = .green copyrightLabel.textColor = .yellow (即appearance)。

2) 另一个可能的问题是在更改外观之前创建此弹出窗口。我的意思是,如果您在外观为color时实例化了此弹出窗口,那么如果您现在将外观更改为.yellow,它将不会自动将弹出窗口的颜色更新为light,因为它已经创建。如果是这种情况,那么您可能必须在dark上进行dark并自己更新所有其他视图颜色。