我编写了这段代码来适应明暗模式:
迅速
let controller:GMSAutocompleteViewController! = GMSAutocompleteViewController()
if #available(iOS 13.0, *) {
if UIScreen.mainScreen.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark {
controller.primaryTextColor = UIColor.whiteColor
controller.secondaryTextColor = UIColor.lightGrayColor
controller.tableCellSeparatorColor = UIColor.lightGrayColor
controller.tableCellBackgroundColor = UIColor.darkGrayColor
} else {
controller.primaryTextColor = UIColor.blackColor
controller.secondaryTextColor = UIColor.lightGrayColor
controller.tableCellSeparatorColor = UIColor.lightGrayColor
controller.tableCellBackgroundColor = UIColor.whiteColor
}
}
Objective-C
GMSAutocompleteViewController *controller = [[GMSAutocompleteViewController alloc] init];
if (@available(iOS 13.0, *)) {
if(UIScreen.mainScreen.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark ){
controller.primaryTextColor = UIColor.whiteColor;
controller.secondaryTextColor = UIColor.lightGrayColor;
controller.tableCellSeparatorColor = UIColor.lightGrayColor;
controller.tableCellBackgroundColor = UIColor.darkGrayColor;
} else {
controller.primaryTextColor = UIColor.blackColor;
controller.secondaryTextColor = UIColor.lightGrayColor;
controller.tableCellSeparatorColor = UIColor.lightGrayColor;
controller.tableCellBackgroundColor = UIColor.whiteColor;
}
}
结果: