Ios UIKit对象控制什么“;“查阅”;弹出式外观?
在我们的应用程序中,我们有一个亮模式和一个暗模式来切换文本颜色和背景颜色<代码>主题是一个Ios UIKit对象控制什么“;“查阅”;弹出式外观?,ios,swift,user-interface,themes,Ios,Swift,User Interface,Themes,在我们的应用程序中,我们有一个亮模式和一个暗模式来切换文本颜色和背景颜色主题是一个枚举,带有大小写亮和暗。我们有切换颜色的方法,例如: 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
枚举
,带有大小写亮
和暗
。我们有切换颜色的方法,例如:
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
方法,将主题应用于我们应用程序中使用的所有视图:
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
}
当一个人在我们的应用程序中选择文本并按下弹出菜单项中的“查找”按钮时,出现的弹出窗口看起来是正确的。但是,当您单击某些视图(如dictionary和siri knowledge)时,背景或文本颜色似乎已更改。例如:
我们如何控制此弹出窗口上的文本颜色
编辑:目标是查找在按下UIMenuItems时创建的UI对象的名称。它不在XCode调试器检查器中,也不在
self.view.subview
中。它似乎是某种内置对象,对其余进程隐藏。可能有一两个问题
1)
您需要确保没有在代码中明确地为标签设置textColor
,为视图设置backgroundColor
<代码>标签
的颜色
应保留默认值
,以便它可以使用外观
颜色
。例如,假设我们已将textColor
设置为默认值,如下图所示
现在,如果我们通过执行UILabel.appearance().textColor=.green
在UILabel
上应用textColor
外观。一旦您打开弹出窗口,它会将颜色
更改为绿色
但是,如果在如下设置外观后显式设置textColor
UILabel.appearance().textColor = .green
copyrightLabel.textColor = .yellow
然后它将放弃外观
设置,并设置您稍后提供的颜色
(即黄色
)
2)
另一个可能的问题可能是在更改外观之前创建此弹出窗口。我的意思是,如果您在外观为亮时实例化了此弹出窗口,那么如果您现在将外观更改为暗
,它将不会自动将弹出窗口颜色更新为暗
,因为它已经创建。如果是这种情况,那么您可能必须在tableView/collectionView
上执行reloadData
,并自己更新所有其他视图颜色。很抱歉回复太晚了——非常感谢,这非常有效!