简体   繁体   中英

How do I dynamically add a badge to the button?

I want to add a badge to the tabs when I receive a new update from DB. Is there a method that I can call to update the IndicatorInfo ?

Unable to figure out please help.

I had to play around with the XIB file, and set constraints and handle cases manually.

Steps Performed

  1. Add constraints to the UIImageView in the ButtonCell.xib file to align itself beside the UILabel . (I added them on a UIView to ensure the views are centred.)
  2. Changed to following code in ButtonBaragerTabStripViewController

     buttonBarItemSpec = .nibFile(nibName: "ButtonCell", bundle: Bundle(for: ButtonBarViewCell.self), width: { [weak self] (childItemInfo) -> CGFloat in let label = UILabel() label.translatesAutoresizingMaskIntoConstraints = false label.font = self?.settings.style.buttonBarItemFont label.text = childItemInfo.title let labelSize = label.intrinsicContentSize return labelSize.width + (childItemInfo.image != nil ? 35.0 : 0.0) + (self?.settings.style.buttonBarItemLeftRightMargin ?? 8) * 2 }) 
  3. Added constraints @IBOutlet and setting it's constant value to 0.0 when image isn't supposed to be there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM