Skip to content

LiuSky/MKBadge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MKBadge

Version License Platform

Requirements:

  • iOS 9.0+
  • Xcode 10.1+
  • Swift 5.0

Installation Cocoapods

pod 'MKBadge', '~> 1.3.1'

Demo Figure

Usage

1. 点角标按钮

private lazy var pointButton: UIButton = {
let temButton = UIButton(type: .custom)
temButton.backgroundColor = UIColor.red
temButton.setTitle("点角标", for: .normal)
temButton.setTitleColor(UIColor.white, for: .normal)
temButton.frame = CGRect(x: self.view.frame.size.width/2 - 44, y: 120, width: 88, height: 44)
temButton.layer.cornerRadius = 22
temButton.badge.type = .point
temButton.badge.positionType = .topRight
return temButton
}()

2.数量角标按钮

private lazy var numberButton: UIButton = {
let temButton = UIButton(type: .custom)
temButton.backgroundColor = UIColor.blue
temButton.setTitle("数量角标", for: .normal)
temButton.setTitleColor(UIColor.white, for: .normal)
temButton.frame = CGRect(x: self.view.frame.size.width/2 - 44, y: self.pointButton.frame.origin.y + 44 + 20, width: 88, height: 44)
temButton.layer.cornerRadius = 22
temButton.badge.type = .count(12)
temButton.badge.fontSize = 12
temButton.badge.height = 14
temButton.badge.positionType = .topLeft
return temButton
}()

3.最小数量按钮

private lazy var minNumberButton: UIButton = {
let temButton = UIButton(type: .custom)
temButton.backgroundColor = UIColor.gray
temButton.setTitle("最小数量角标", for: .normal)
temButton.setTitleColor(UIColor.white, for: .normal)
temButton.frame = CGRect(x: self.view.frame.size.width/2 - 60, y: self.numberButton.frame.origin.y + 44 + 20, width: 120, height: 44)
temButton.layer.cornerRadius = 22
temButton.badge.type = .count(1)
temButton.badge.height = 14
return temButton
}()

4.最大数量按钮

private lazy var maxNumberButton: UIButton = {
let temButton = UIButton(type: .custom)
temButton.backgroundColor = UIColor.black
temButton.setTitle("最大数量角标", for: .normal)
temButton.setTitleColor(UIColor.white, for: .normal)
temButton.frame = CGRect(x: self.view.frame.size.width/2 - 60, y: self.minNumberButton.frame.origin.y + 44 + 20, width: 120, height: 44)
temButton.layer.cornerRadius = 22
temButton.badge.positionType = .bottomLeft
temButton.badge.type = .count(100)
temButton.badge.height = 14
return temButton
}()

5.颜色角标按钮

private lazy var colorButton: UIButton = {
let temButton = UIButton(type: .custom)
temButton.backgroundColor = UIColor.green
temButton.setTitle("背景颜色角标", for: .normal)
temButton.setTitleColor(UIColor.white, for: .normal)
temButton.frame = CGRect(x: self.view.frame.size.width/2 - 60, y: self.maxNumberButton.frame.origin.y + 44 + 20, width: 120, height: 44)
temButton.layer.cornerRadius = 22
temButton.badge.type = .count(12)
temButton.badge.height = 14
temButton.badge.backgroundColor = UIColor.black
temButton.badge.positionType = .bottomRight
return temButton
}()

6.角标文本颜色按钮

private lazy var textColorButton: UIButton = {
let temButton = UIButton(type: .custom)
temButton.backgroundColor = UIColor.purple
temButton.setTitle("背景颜色角标", for: .normal)
temButton.setTitleColor(UIColor.white, for: .normal)
temButton.frame = CGRect(x: self.view.frame.size.width/2 - 60, y: self.colorButton.frame.origin.y + 44 + 20, width: 120, height: 44)
temButton.layer.cornerRadius = 22
temButton.badge.type = .count(12)
temButton.badge.height = 14
temButton.badge.backgroundColor = UIColor.lightGray
temButton.badge.textColor = UIColor.red
return temButton
}()

7.左对齐角标按钮

private lazy var leftButton: UIButton = {
let temButton = UIButton(type: .custom)
temButton.backgroundColor = UIColor.brown
temButton.setTitle("左对齐角标", for: .normal)
temButton.setTitleColor(UIColor.white, for: .normal)
temButton.frame = CGRect(x: self.view.frame.size.width/2 - 60, y: self.textColorButton.frame.origin.y + 44 + 20, width: 120, height: 44)
temButton.layer.cornerRadius = 22
temButton.badge.positionType = .topLeft
temButton.badge.type = .count(100)
temButton.badge.height = 14
return temButton
}()

8.变化角标按钮

private lazy var changeButton: UIButton = {
let temButton = UIButton(type: .custom)
temButton.backgroundColor = UIColor.magenta
temButton.setTitle("点击按钮", for: .normal)
temButton.setTitleColor(UIColor.white, for: .normal)
temButton.frame = CGRect(x: self.view.frame.size.width/2 - 60, y: self.leftButton.frame.origin.y + 44 + 20, width: 120, height: 44)
temButton.layer.cornerRadius = 22
temButton.layer.cornerRadius = 22
temButton.badge.type = .count(12)
temButton.badge.height = 14
temButton.addTarget(self, action: #selector(eventForChange(_:)), for: .touchUpInside)
return temButton
}()

Reference

License

MKBadge is released under an MIT license. See LICENSE for more information.