所以我处于一个稍微复杂的情况,
问题:我的自定义UITableViewSectionHeader 只有在导航栏下方有一条细蓝线,我不知道它来自哪里:
我有:
嵌套在UIViewController
直接在我的NavigationBar下的GradientView(继承UIView)
[
我的理论:
该边界线来自: - 导航栏的下边框 - tableview的顶部边框 - 可能是Section头中的分隔符(但似乎不太可能) - GradientView的底部边框
有人知道可能导致这条线的原因吗?
我试图将其删除: 的ViewController:
SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create
GradientView:
override func viewDidLoad() {
// self.tableview.separatorStyle = .none
// self.tableview.layer.borderWidth = 0
// self.view.layer.borderWidth = 0
}
SectionHeader:
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.layer.borderWidth = 0
}
有什么想法?
答案 0 :(得分:0)
导航栏的图像视图的线条介于小于或等于1px之间,您需要遍历NavigationController navigationBar以找到该图像并将其设置为隐藏。
您可以直接在navigationBar上循环并查找所有子视图,或者如果您想要查看视图,那么我将如何完成它。
var lineImageView: UIImageView? = { [unowned self] in
// guard is great try to use it whenever you can
guard let navigationBar = self.navigationController?.navigationBar else {
return nil
}
return self.findLineImageView(for: navigationBar)
}()
现在添加这个循环的函数,直到它找到一个imageView并将它返回给我们的lineImageView
// remember even **navigationBar** is a UI remember **UINavigationBar**
func findLineImageView(for view: UIView) -> UIImageView? {
// as I said above the line is not more than 1px so we look for a view which is less than or equals to 1px in height
if view is UIImageView && view.bounds.size.height <= 1 {
return (view as! UIImageView)
}
// we loop till we find the line image view and return it
for subview in view.subviews {
if let imageView = findLineImageView(for: subview) {
return imageView
}
}
// if there is no imageView with that height we return nil that's why we return an optional UIImageView
return nil
}
现在神奇的部分。在 viewWillApear 中将 lineImageView 设置为隐藏
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// remember as I said the lineImageView we returned an optional that's why it has question mark which means we are safe
lineImageView?.isHidden = true
}