         tap.addTarget(self, action: #selector(WMFTableOfContentsPresentationController.didTap(_:)))
         view.addGestureRecognizer(tap)
         view.contentView.addSubview(self.statusBarBackground)
+
+        let closeButtonDimension: CGFloat = 44
+        let widthConstraint = self.closeButton.widthAnchor.constraint(equalToConstant: closeButtonDimension)
+        let heightConstraint = self.closeButton.heightAnchor.constraint(equalToConstant: closeButtonDimension)
+
+        let leadingConstraint = view.contentView.layoutMarginsGuide.leadingAnchor.constraint(equalTo: self.closeButton.leadingAnchor, constant: 0)
+        let trailingConstraint = view.contentView.layoutMarginsGuide.trailingAnchor.constraint(equalTo: self.closeButton.trailingAnchor, constant: 0)
+        let topConstraint = view.contentView.layoutMarginsGuide.topAnchor.constraint(equalTo: self.closeButton.topAnchor, constant: 0)
+        let bottomConstraint = view.contentView.layoutMarginsGuide.bottomAnchor.constraint(equalTo: self.closeButton.bottomAnchor, constant: 0)
+        trailingConstraint.isActive = false
+        bottomConstraint.isActive = false
+        closeButtonLeadingConstraint = leadingConstraint
+        closeButtonTrailingConstraint = trailingConstraint
+        closeButtonTopConstraint = topConstraint
+        closeButtonBottomConstraint = bottomConstraint
+        self.closeButton.frame = CGRect(x: 0, y: 0, width: closeButtonDimension, height: closeButtonDimension)
+        self.closeButton.addConstraints([widthConstraint, heightConstraint])
         view.contentView.addSubview(self.closeButton)
+        view.contentView.addConstraints([leadingConstraint, trailingConstraint, topConstraint, bottomConstraint])
+
         return view
     }()
 


    open var minimumVisibleBackgroundWidth: CGFloat = 60.0
    open var maximumTableOfContentsWidth: CGFloat = 300.0
    open var closeButtonLeadingPadding: CGFloat = 10.0
    open var closeButtonTopPadding: CGFloat = 0.0
    open var statusBarEstimatedHeight: CGFloat {
        if #available(iOS 11.0, *) {
            return max(UIApplication.shared.statusBarFrame.size.height, presentedView?.safeAreaInsets.top ?? 0)

import UIKit

// MARK: - Delegate
@objc public protocol WMFTableOfContentsPresentationControllerTapDelegate {
