From fa5aba357e4a4f1587d6aac230d1c8e56a59ba71 Mon Sep 17 00:00:00 2001 From: Aliona Date: Mon, 15 Jan 2018 16:38:41 +0300 Subject: [PATCH] Add constraints --- .../UITableView/UITableView+Extensions.swift | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Sources/Extensions/UITableView/UITableView+Extensions.swift b/Sources/Extensions/UITableView/UITableView+Extensions.swift index 6c6cf7f4..c6440a8a 100644 --- a/Sources/Extensions/UITableView/UITableView+Extensions.swift +++ b/Sources/Extensions/UITableView/UITableView+Extensions.swift @@ -27,14 +27,15 @@ public extension UITableView { /// Adds colored background to the top of the tableview. /// /// - Parameters: - /// - color: background color + /// - color: header background color func addHeaderBackground(with color: UIColor) { - let backgroundFrame = CGRect(x: frame.origin.x, - y: -bounds.height, - width: UIScreen.main.bounds.width, - height: bounds.height) - let backgroundView = UIView(frame: backgroundFrame) + let backgroundView = UIView() backgroundView.backgroundColor = color addSubview(backgroundView) + backgroundView.translatesAutoresizingMaskIntoConstraints = false + backgroundView.leftAnchor.constraint(equalTo: leftAnchor).isActive = true + backgroundView.bottomAnchor.constraint(equalTo: topAnchor).isActive = true + backgroundView.widthAnchor.constraint(equalTo: widthAnchor).isActive = true + backgroundView.heightAnchor.constraint(equalTo: heightAnchor).isActive = true } }