Skip to content

Latest commit

 

History

History
76 lines (58 loc) · 1.7 KB

README.md

File metadata and controls

76 lines (58 loc) · 1.7 KB

ACBadge

Swift3.0/4.0版本的右上角未读红点

安装

CocoaPods

  • 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.4.2'

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 // 数字红点的最大值,超过这个值,显示“这个值+”

为UIView添加红点

view.ac_showBadge(with: .redDot)
// 或者 view.ac_showRedDot(true)
view.ac_showBadge(with: .number(with: 999)) // number传0时消失
view.ac_clearBadge() // 清除红点

为UITabBarItem添加红点

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() // 清除红点

为UIBarButtonItem添加红点(1.4.0版本暂时去掉此功能)

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() // 清除红点