Swift3.0/4.0版本的右上角未读红点
- swift 3:
pod 'ACBadge', '~> 1.3.0'
- swift 4:
pod 'ACBadge', '~> 1.4.0'
- swift 4.2:
pod 'ACBadge', '~> 1.4.1'
- swift 5.0:
pod 'ACBadge', '~> 1.5.0'
Then, run the following command:
$ pod install
ACBadge.default.redDotWidth = 20
ACBadge.default.backgroundColor = UIColor.red
ACBadge.default.textColor = UIColor.white
ACBadge.default.font = UIFont.systemFont(ofSize: 15)
ACBadge.default.maximumNumber = 99 // 数字红点的最大值,超过这个值,显示“这个值+”
view.ac_showBadge(with: .redDot)
// 或者 view.ac_showRedDot(true)
view.ac_showBadge(with: .number(with: 999)) // number传0时消失
view.ac_clearBadge() // 清除红点
let firstItem = tabBarController?.tabBar.items?.first
firstItem.ac_showBadge(with: .redDot)
// 或者 firstItem.ac_showRedDot(true)
firstItem.ac_showBadge(with: .number(with: 999)) // number传0时红点消失
firstItem.ac_clearBadge() // 清除红点
let leftItem = UIBarButtonItem(image: #imageLiteral(resourceName: "user01"), style: .plain, target: self, action: #selector(barButtonClicked))
navigationItem.leftBarButtonItem = leftItem
leftItem.ac_badgeRedDotWidth = 8
leftItem.ac_badgeCenterOffset = CGPoint(x: -8, y: 0)
leftItem.ac_showRedDot(true)
leftItem.ac_clearBadge() // 清除红点