Skip to content

Commit 2fdcbd3

Browse files
author
Beata Lin
committed
Re-calculate touch area in layoutSubview
1 parent a72b3ae commit 2fdcbd3

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Source/BTNavigationDropdownMenu.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,13 +406,21 @@ open class BTNavigationDropdownMenu: UIView {
406406
}
407407

408408
override open func layoutSubviews() {
409+
let titleToDisplay = self.menuTitle.text ?? ""
410+
let titleSize = (titleToDisplay as NSString).size(withAttributes: [NSAttributedString.Key.font:self.configuration.navigationBarTitleFont])
411+
let frame = CGRect(x: 0, y: 0, width: titleSize.width + (self.configuration.arrowPadding + self.configuration.arrowImage.size.width)*2, height: self.navigationController!.navigationBar.frame.height)
412+
413+
414+
self.frame = frame
415+
409416
self.menuTitle.sizeToFit()
410417
self.menuTitle.center = CGPoint(x: self.frame.size.width/2, y: self.frame.size.height/2)
411418
self.menuTitle.textColor = self.configuration.menuTitleColor
412419
self.menuArrow.sizeToFit()
413420
self.menuArrow.center = CGPoint(x: self.menuTitle.frame.maxX + self.configuration.arrowPadding, y: self.frame.size.height/2)
414421
self.menuImage.sizeToFit()
415422
self.menuImage.center = CGPoint(x: self.menuTitle.frame.minX - ((self.menuImage.image?.size.width ?? 0) / 2), y: self.frame.size.height/2)
423+
self.menuButton.frame = frame
416424
self.menuWrapper.frame.origin.y = self.navigationController!.navigationBar.frame.maxY
417425
self.tableView.reloadData()
418426
}
@@ -446,7 +454,6 @@ open class BTNavigationDropdownMenu: UIView {
446454

447455
open func updateItemImages(_ images: [UIImage]?) {
448456
self.tableView.itemImages = images
449-
self.tableView.reloadData()
450457
}
451458

452459
open func setSelected(index: Int) {
@@ -554,11 +561,11 @@ open class BTNavigationDropdownMenu: UIView {
554561
}
555562
})
556563
}
557-
564+
558565
func setMenuTitle(_ title: String) {
559566
self.menuTitle.text = title
560567
}
561-
568+
562569
func setMenuImage(_ image: UIImage) {
563570
self.menuImage.image = image
564571
}

0 commit comments

Comments
 (0)