作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我在 iOS 中使用 Google 自动完成 placekicker。它向我展示了具有原生设计的 Controller 。我想自定义它的导航栏颜色。但我做不到。下面是代码
let autocompleteController = GMSAutocompleteViewController()
autocompleteController.tintColor = UIColor.red
autocompleteController.navigationController?.navigationBar.barTintColor = Constant.AppColor.navigationColor
autocompleteController.delegate = self
self.present(autocompleteController, animated: true, completion: nil)
最佳答案
我写了这段代码来适应亮/暗模式:
swift
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;
}
}
结果:
关于ios - 如何为 iOS 自定义 GMSAutocompleteViewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48072787/
我是一名优秀的程序员,十分优秀!