iOS 9在UINavigationController和UISearchBar之间发际线

时间:2016-01-18 15:33:45

标签: ios swift2 uinavigationbar ios9 uisearchcontroller

我有UINavigationController,其中UISearchController以编程方式放置。

searchController.searchBar.barTintColor = UIColor(red: 242/255.0, green: 82/255.0, blue: 46/255.0, alpha: 0.4)
searchController.searchBar.translucent = false
searchController.searchBar.layer.borderColor = UIColor.whiteColor().CGColor
searchController.searchBar.layer.borderWidth = 0

我像上面那样设置我的UISearchController。 我将UINavigationBar设计全局设置为全局:

UINavigationBar.appearance().translucent = false
UINavigationBar.appearance().barTintColor = UIColor(red: 242/255.0, green: 82/255.0, blue: 46/255.0, alpha: 1.0)
UINavigationBar.appearance().shadowImage = UIImage()
UINavigationBar.appearance().setBackgroundImage(UIImage(), forBarPosition: .Any, barMetrics: .Default)
UINavigationBar.appearance().layer.shadowRadius = 0
UINavigationBar.appearance().layer.shadowOpacity = 0
UINavigationBar.appearance().layer.shadowOffset = CGSizeMake(0,0)
UINavigationBar.appearance().titleTextAttributes = [
    NSForegroundColorAttributeName: UIColor.whiteColor(),
    NSFontAttributeName: UIFont(name: "JosefinSans-SemiBold", size: 18)!
]

它应该删除1px发线边界,但事实并非如此。我读到这是因为阴影图像,但我似乎无法删除1px发际线。 谁可以帮助我?

1 个答案:

答案 0 :(得分:1)

尝试替换它:

searchController.searchBar.layer.borderColor = UIColor.whiteColor().CGColor
searchController.searchBar.layer.borderWidth = 0

用这个:

searchController.searchBar.layer.borderColor = UIColor(red: 242/255.0, green: 82/255.0, blue: 46/255.0, alpha: 1).CGColor
searchController.searchBar.layer.borderWidth = 1