@@ -41,19 +41,19 @@ class ICToken: UIView {
41
41
}
42
42
}
43
43
44
- var normalTextAttributes : [ String : NSObject ] = [
45
- NSForegroundColorAttributeName : UIColor ( red: 0.14 , green: 0.38 , blue: 0.95 , alpha: 1 ) ,
46
- NSBackgroundColorAttributeName : UIColor . clear
44
+ var normalTextAttributes : [ NSAttributedStringKey : NSObject ] = [
45
+ . foregroundColor : UIColor ( red: 0.14 , green: 0.38 , blue: 0.95 , alpha: 1 ) ,
46
+ . backgroundColor : UIColor . clear
47
47
] {
48
48
didSet {
49
49
if !isHighlighted { updateTextLabel ( ) }
50
- delimiterLabel. textColor = self . normalTextAttributes [ NSForegroundColorAttributeName ] as? UIColor
50
+ delimiterLabel. textColor = self . normalTextAttributes [ . foregroundColor ] as? UIColor
51
51
}
52
52
}
53
53
54
- var highlightedTextAttributes : [ String : NSObject ] = [
55
- NSForegroundColorAttributeName : UIColor . white,
56
- NSBackgroundColorAttributeName : UIColor ( red: 0.14 , green: 0.38 , blue: 0.95 , alpha: 1 )
54
+ var highlightedTextAttributes : [ NSAttributedStringKey : NSObject ] = [
55
+ . foregroundColor : UIColor . white,
56
+ . backgroundColor : UIColor ( red: 0.14 , green: 0.38 , blue: 0.95 , alpha: 1 )
57
57
] {
58
58
didSet {
59
59
if isHighlighted { updateTextLabel ( ) }
@@ -64,16 +64,16 @@ class ICToken: UIView {
64
64
65
65
private( set) lazy var delimiterLabel : UILabel = {
66
66
let _label = UILabel ( )
67
- _label. textColor = self . normalTextAttributes [ NSForegroundColorAttributeName ] as? UIColor
67
+ _label. textColor = self . normalTextAttributes [ . foregroundColor ] as? UIColor
68
68
_label. textAlignment = . right
69
69
return _label
70
70
} ( )
71
71
72
72
private( set) lazy var textLabel : UILabel = {
73
73
let _label = ICInsetLabel ( contentEdgeInsets: UIEdgeInsets ( top: 3 , left: 5 , bottom: 3 , right: 5 ) , cornerRadius: . constant( 3 ) )
74
74
_label. textAlignment = . center
75
- _label. textColor = self . normalTextAttributes [ NSForegroundColorAttributeName ] as? UIColor
76
- _label. backgroundColor = self . normalTextAttributes [ NSBackgroundColorAttributeName ] as? UIColor
75
+ _label. textColor = self . normalTextAttributes [ . foregroundColor ] as? UIColor
76
+ _label. backgroundColor = self . normalTextAttributes [ . backgroundColor ] as? UIColor
77
77
_label. numberOfLines = 1
78
78
return _label
79
79
} ( )
@@ -90,7 +90,12 @@ class ICToken: UIView {
90
90
setUpSubviews ( )
91
91
}
92
92
93
- convenience init ( text: String , delimiter: String = " , " , normalAttributes: [ String : NSObject ] ? = nil , highlightedAttributes: [ String : NSObject ] ? = nil ) {
93
+ convenience init (
94
+ text: String ,
95
+ delimiter: String = " , " ,
96
+ normalAttributes: [ NSAttributedStringKey : NSObject ] ? = nil ,
97
+ highlightedAttributes: [ NSAttributedStringKey : NSObject ] ? = nil
98
+ ) {
94
99
self . init ( )
95
100
if let attributes = normalAttributes { normalTextAttributes = attributes }
96
101
if let attributes = highlightedAttributes { highlightedTextAttributes = attributes }
@@ -105,15 +110,15 @@ class ICToken: UIView {
105
110
106
111
private func updateTextLabel( ) {
107
112
var attributes = isHighlighted ? highlightedTextAttributes : normalTextAttributes
108
- if let color = attributes [ NSBackgroundColorAttributeName ] as? UIColor {
113
+ if let color = attributes [ . backgroundColor ] as? UIColor {
109
114
textLabel. backgroundColor = color
110
115
}
111
116
// Avoid overlapped translucent background colors
112
- attributes [ NSBackgroundColorAttributeName ] = nil
117
+ attributes [ . backgroundColor ] = nil
113
118
textLabel. attributedText = NSAttributedString ( string: text, attributes: attributes)
114
119
115
- delimiterLabel. textColor = normalTextAttributes [ NSForegroundColorAttributeName ] as? UIColor
116
- delimiterLabel. font = normalTextAttributes [ NSFontAttributeName ] as? UIFont
120
+ delimiterLabel. textColor = normalTextAttributes [ . foregroundColor ] as? UIColor
121
+ delimiterLabel. font = normalTextAttributes [ . font ] as? UIFont
117
122
}
118
123
119
124
private func setUpSubviews( ) {
0 commit comments