I have a bar button item on my view controller which is showing a popover view, and I have an extension to show badges on any button, I tried to show the badges on the icon but it shows me another view, and I want to show the badges on my bar button item,
I tried this code
func addBadge(itemvalue: String) {
let bagButton = BadgeButton()
bagButton.frame = CGRect(x: 0, y: 0, width: 44, height: 44)
bagButton.tintColor = UIColor.darkGray
bagButton.setImage(UIImage(named: "comment")?.withRenderingMode(.alwaysTemplate), for: .normal)
bagButton.badgeEdgeInsets = UIEdgeInsets(top: 20, left: 0, bottom: 0, right: 15)
bagButton.badge = itemvalue
self.navigationItem.rightBarButtonItem = UIBarButtonItem(customView: bagButton)
}
my popover button code
@IBAction func showPopoverButtonAction(_ sender: Any) {
//get the button frame
/* 1 */
let button = sender as? UIButton
let buttonFrame = button?.frame ?? CGRect.init(x: -20, y: -320, width: 200, height: 400)
/* 2 */
//Configure the presentation controller
guard let popoverContentController = self.storyboard?.instantiateViewController(withIdentifier: "PopOverViewController") as? PopOverViewController else { return }
popoverContentController.modalPresentationStyle = .popover
popoverContentController.dpostID = self.postIdm
popoverContentController.dpostTitle = self.postTitlem
popoverContentController.duserPhone = self.muserPhone
popoverContentController.delegate = self
/* 3 */
if let popoverPresentationController = popoverContentController.popoverPresentationController {
popoverPresentationController.permittedArrowDirections = .up
popoverPresentationController.sourceView = self.view
popoverPresentationController.sourceRect = buttonFrame
popoverPresentationController.delegate = self
// if let popoverController = popoverContentController {
//
// }
present(popoverContentController, animated: true, completion: nil)
}
}
currently it is showing like this! enter image description here
but I want the badges to be on my bar button not new button!
to clarify: the new bar button with badge is generated by the code in the question, and the comment button is mybutton which I want to show the badges on.
popover button is the button that I want to show the badges on instead of the generated button from the code