@@ -101,6 +101,7 @@ open class DropdownMenu: UIView {
101101
102102 clipsToBounds = true
103103 setupGestureView ( )
104+ initTableView ( )
104105
105106 NotificationCenter . default. addObserver ( self , selector: #selector( self . updateForOrientationChange ( _: ) ) , name: NSNotification . Name. UIApplicationWillChangeStatusBarOrientation, object: nil )
106107 }
@@ -115,6 +116,7 @@ open class DropdownMenu: UIView {
115116
116117 clipsToBounds = true
117118 setupGestureView ( )
119+ initTableView ( )
118120
119121 NotificationCenter . default. addObserver ( self , selector: #selector( self . updateForOrientationChange ( _: ) ) , name: NSNotification . Name. UIApplicationWillChangeStatusBarOrientation, object: nil )
120122 }
@@ -159,36 +161,40 @@ open class DropdownMenu: UIView {
159161 gestureView. addGestureRecognizer ( UITapGestureRecognizer ( target: self , action: #selector( hideMenu) ) )
160162 }
161163
162- fileprivate func setupTopSeperatorView( ) {
163- let seperatorView = UIView ( )
164- seperatorView. backgroundColor = tableViewSeperatorColor
165- addSubview ( seperatorView)
166- seperatorView. translatesAutoresizingMaskIntoConstraints = false
167- NSLayoutConstraint . activate ( [ NSLayoutConstraint . init ( item: seperatorView, attribute: . top, relatedBy: . equal, toItem: self , attribute: . top, multiplier: 1.0 , constant: 0 ) ] )
168- NSLayoutConstraint . activate ( [ NSLayoutConstraint . init ( item: seperatorView, attribute: . left, relatedBy: . equal, toItem: self , attribute: . left, multiplier: 1.0 , constant: 0 ) ] )
169- NSLayoutConstraint . activate ( [ NSLayoutConstraint . init ( item: seperatorView, attribute: . right, relatedBy: . equal, toItem: self , attribute: . right, multiplier: 1.0 , constant: 0 ) ] )
170- NSLayoutConstraint . activate ( [ NSLayoutConstraint . init ( item: seperatorView, attribute: . height, relatedBy: . equal, toItem: nil , attribute: . notAnAttribute, multiplier: 1.0 , constant: 0.5 ) ] )
164+ fileprivate func initTableView( ) {
165+ tableView = UITableView ( frame: CGRect . zero, style: . grouped)
166+ tableView. separatorStyle = separatorStyle
167+ tableView? . delegate = self
168+ tableView? . dataSource = self
169+ addSubview ( tableView)
171170 }
172171
173- fileprivate func setupTableView( ) {
172+ fileprivate func layoutTableView( ) {
173+ tableView. translatesAutoresizingMaskIntoConstraints = false
174+
174175 tableViewHeight = tableviewHeight ( )
175176 let maxHeight = navigationController. view. frame. height - topLayoutConstraintConstant - defaultBottonMargin
176177 if tableViewHeight > maxHeight {
177178 tableViewHeight = maxHeight
178179 }
179180
180- tableView = UITableView ( frame: CGRect . zero, style: . grouped)
181- tableView. separatorStyle = separatorStyle
182- tableView? . delegate = self
183- tableView? . dataSource = self
184- addSubview ( tableView)
185- tableView. translatesAutoresizingMaskIntoConstraints = false
186181 NSLayoutConstraint . activate ( [ NSLayoutConstraint . init ( item: tableView, attribute: . top, relatedBy: . equal, toItem: self , attribute: . top, multiplier: 1.0 , constant: 0 ) ] )
187182 NSLayoutConstraint . activate ( [ NSLayoutConstraint . init ( item: tableView, attribute: . height, relatedBy: . equal, toItem: nil , attribute: . notAnAttribute, multiplier: 1.0 , constant: tableViewHeight) ] )
188183 NSLayoutConstraint . activate ( [ NSLayoutConstraint . init ( item: tableView, attribute: . left, relatedBy: . equal, toItem: self , attribute: . left, multiplier: 1.0 , constant: 0 ) ] )
189184 NSLayoutConstraint . activate ( [ NSLayoutConstraint . init ( item: tableView, attribute: . right, relatedBy: . equal, toItem: self , attribute: . right, multiplier: 1.0 , constant: 0 ) ] )
190185 }
191186
187+ fileprivate func setupTopSeperatorView( ) {
188+ let seperatorView = UIView ( )
189+ seperatorView. backgroundColor = tableViewSeperatorColor
190+ addSubview ( seperatorView)
191+ seperatorView. translatesAutoresizingMaskIntoConstraints = false
192+ NSLayoutConstraint . activate ( [ NSLayoutConstraint . init ( item: seperatorView, attribute: . top, relatedBy: . equal, toItem: self , attribute: . top, multiplier: 1.0 , constant: 0 ) ] )
193+ NSLayoutConstraint . activate ( [ NSLayoutConstraint . init ( item: seperatorView, attribute: . left, relatedBy: . equal, toItem: self , attribute: . left, multiplier: 1.0 , constant: 0 ) ] )
194+ NSLayoutConstraint . activate ( [ NSLayoutConstraint . init ( item: seperatorView, attribute: . right, relatedBy: . equal, toItem: self , attribute: . right, multiplier: 1.0 , constant: 0 ) ] )
195+ NSLayoutConstraint . activate ( [ NSLayoutConstraint . init ( item: seperatorView, attribute: . height, relatedBy: . equal, toItem: nil , attribute: . notAnAttribute, multiplier: 1.0 , constant: 0.5 ) ] )
196+ }
197+
192198 fileprivate func setupNavigationBarCoverView( on view: UIView ) {
193199 barCoverView = UIView ( )
194200 barCoverView? . backgroundColor = UIColor . clear
@@ -223,7 +229,7 @@ open class DropdownMenu: UIView {
223229
224230 isShow = true
225231
226- setupTableView ( )
232+ layoutTableView ( )
227233 setupTopSeperatorView ( )
228234
229235 if let rootView = UIApplication . shared. keyWindow {
0 commit comments