UITabBar+CNLiveExtensions.swift
6.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
//
// UITabBar+CNBadge.swift
// metaCode
//
// Created by daojian on 2023/6/5.
//
import Foundation
import UIKit
//extension UITabBar {
// /**
// tabbar tag
// */
// private var badgeTag:Int! {
// get{
// return 1000
// }
// set{
//
// }
// }
//
// /**
// 运行时对应的key值
// */
// private struct AssociatedKeys {
// static var kBadgeSize:String! = "kBadgeSize"
// static var kBadgeColor:String! = "kBadgeColor"
// static var kBadgeImage:String! = "kBadgeImage"
// static var kBadgePoint:String! = "kBadgePoint"
// static var kBadgeValue:String! = "kBadgeValue"
// }
//
//
// // 小红点size
// public var badgeSize:CGSize! {
// get{
// return objc_getAssociatedObject(self, &AssociatedKeys.kBadgeSize) as? CGSize
// }
// set{
// objc_setAssociatedObject(self, &AssociatedKeys.kBadgeSize, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
// }
// }
//
// // 小红点图片
// public var badgeImage:UIImage! {
// get{
// return objc_getAssociatedObject(self, &AssociatedKeys.kBadgeImage) as? UIImage
// }
// set{
// objc_setAssociatedObject(self, &AssociatedKeys.kBadgeImage, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
// }
// }
//
// // 小红点颜色
// public var badgeColor:UIColor! {
// get{
// return objc_getAssociatedObject(self, &AssociatedKeys.kBadgeColor) as? UIColor
// }
// set{
// objc_setAssociatedObject(self, &AssociatedKeys.kBadgeColor, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
// }
// }
//
// // 小红点的x、y值
// public var badgePoint:CGPoint! {
// get{
// return objc_getAssociatedObject(self, &AssociatedKeys.kBadgePoint) as? CGPoint
// }
// set{
// objc_setAssociatedObject(self, &AssociatedKeys.kBadgePoint, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
// }
// }
//
// // 小红点的数字
// public var badgeValue:String! {
// get{
// return objc_getAssociatedObject(self, &AssociatedKeys.kBadgeValue) as? String
// }
// set{
// objc_setAssociatedObject(self, &AssociatedKeys.kBadgeValue, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
// }
// }
//
// // MARK:-显示小红点
// public func showBadgeOnItemIndex(index:Int){
// // 移除
// self.removeRedPointOnIndex(index: index, animation: false)
//
// // 防止是空的
// if self.badgeColor == nil {
// self.badgeColor = UIColor()
// self.badgeColor = UIColor.red
// }
//
// if self.badgePoint == nil {
// self.badgePoint = CGPoint()
// self.badgePoint = CGPoint.zero
// }
//
// if self.badgeSize == nil {
// self.badgeSize = CGSize.zero
// }
//
// if self.badgeImage == nil {
// self.badgeImage = UIImage()
// }
//
// if self.badgeValue == nil {
// self.badgeValue = String()
// }
//
// // 小红点背景默认值大小设置
// if __CGSizeEqualToSize(self.badgeSize, CGSize.zero) {
// self.badgeSize = CGSize(width: 12, height: 12)
// }
//
//
// let badgeView = UIView()
// badgeView.backgroundColor = self.badgeColor
// badgeView.layer.cornerRadius = self.badgeSize.width / 2
// badgeView.tag = badgeTag + 1
//
// let barButtonView = self.getBarButttonViewWithIndex(index: index)
// //(图片的imageView)
// var iconView = UIView()
// for swappableImageView in barButtonView.subviews {
//
// if swappableImageView.isKind(of: UIImageView.self) {
// iconView = swappableImageView
// break
// }
//
// }
//
// // 小红点背景默认值Point设置
// if __CGPointEqualToPoint(self.badgePoint, CGPoint.zero) {
// let iconViewSize = iconView.frame.size
// badgeView.frame = CGRect(x: iconViewSize.width - self.badgeSize.width / 2, y: -self.badgeSize.width / 2, width: self.badgeSize.width, height: self.badgeSize.height)
// }else{
// badgeView.frame = CGRect(x: self.badgePoint.x, y: self.badgePoint.y, width: self.badgeSize.width, height: self.badgeSize.height)
// }
//
// // 添加图片到小红点上
// let imageview = UIImageView(frame: badgeView.bounds)
// imageview.image = self.badgeImage
// if self.badgeImage != nil {
// self.backgroundColor = UIColor.red
// }
// badgeView.addSubview(imageview)
//
// if self.badgeValue != nil {
// let badgeLabel = UILabel(frame: badgeView.bounds)
// badgeLabel.text = self.badgeValue
// badgeLabel.textAlignment = .center
// badgeLabel.font = UIFont.systemFont(ofSize: 13)
// badgeLabel.textColor = UIColor.white
// badgeView.addSubview(badgeLabel)
// }
//
// iconView.addSubview(badgeView)
// }
//
// // MARK:-隐藏小红点
// public func hiddenRedPointOnIndex(index:Int, animation:Bool){
// self.removeRedPointOnIndex(index: index, animation: animation)
// }
//
// private func removeRedPointOnIndex(index:Int, animation:Bool) {
// let barButtonView = self.getBarButttonViewWithIndex(index: index)
//
// for swapView in barButtonView.subviews {
//
// if swapView.isKind(of: UIImageView.self) {
//
// for view1 in swapView.subviews {
//
// if view1.tag == (badgeTag + 1) {
//
// if animation {
// UIView.animate(withDuration: 0.2, animations: {
// view1.transform = CGAffineTransform(translationX: 2, y: 2)
// view1.alpha = 0
// }) { (finished) in
// view1.removeFromSuperview()
// }
// }else{
// view1.removeFromSuperview()
// }
//
// }
//
// }
//
// }
//
// }
//
// }
//
// // 获取barButtonView
// private func getBarButttonViewWithIndex(index:Int) -> UIView {
//
// if let itemss = self.items {
// let item = itemss[index]
// let barButtonView = item.value(forKey: "view")
// return barButtonView as! UIView
// }
//
// let vw = UIView()
// return vw
// }
//
//}