- iOS 9.0+
- Xcode 10.1+
- Swift 5.0
pod 'MKBadge', '~> 1.3.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
}()
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
}()
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
}()
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
}()
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
}()
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
}()
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
}()
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
}()
MKBadge is released under an MIT license. See LICENSE for more information.