我想在收到来自 DB 的新更新时向选项卡添加角标(Badge)。有没有我可以调用的方法来更新 IndicatorInfo
?
无法弄清楚请帮助。
最佳答案
我不得不使用 XIB 文件,手动设置约束和处理案例。
执行的步骤
- 向
ButtonCell.xib
文件中的UIImageView
添加约束,使其与UILabel
对齐。 (我将它们添加到UIView
以确保 View 居中。) 更改为
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 })
- 添加了约束
@IBOutlet
并将它的constant
值设置为0.0
当图像不应该存在时。
关于ios - 如何为按钮动态添加角标(Badge)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46902248/