YSBadge
自定义视图角标_swift编写,使用简单,样式灵活。
环境
swift5.0、iOS10.0
使用步骤
1、导入框架
pod 'YSBadge'
2、导入命名空间
import YSBadge
使用示例
import UIKit
import YSBadge
class ViewController: UIViewController {
private lazy var testView:UIView = {
let frame = CGRect(x: 100, y: 100, width: 100, height: 100)
let v = UIView(frame: frame)
v.backgroundColor = UIColor.yellow
return v
}()
private lazy var testBtn:UIButton = {
let btn = UIButton(type: .contactAdd)
btn.addTarget(self, action: #selector(btnClick), for: .touchUpInside)
return btn
}()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(testView)
view.addSubview(testBtn)
testBtn.frame.origin = CGPoint(x: 140, y: 250)
}
@objc private func btnClick(){
// 设置badge样式
// font:字体
// textColor:文字颜色
// badgeColor:填充颜色
// borderColor:边框颜色
// borderWidth:边框线宽
// minDiameter:最小直径
// horizontalOffset:水平偏移量
// verticalOffset:垂直偏移量
// innerSpaceFromBorder:文字与边框的间距
// position:位置
testView.ysBadgeView.setStyle(font: UIFont.systemFont(ofSize: 12), textColor: UIColor.white, badgeColor: UIColor.red, borderColor: nil, borderWidth: nil, minDiameter: 20, horizontalOffset: nil, verticalOffset: nil, innerSpaceFromBorder: nil, position: .topTrailing)
// 设置badge值
testView.ysBadgeView.badgeValue = "9"
}
}