@@ -41,19 +41,19 @@ class ICToken: UIView {
4141 }
4242 }
4343
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
4747 ] {
4848 didSet {
4949 if !isHighlighted { updateTextLabel ( ) }
50- delimiterLabel. textColor = self . normalTextAttributes [ NSForegroundColorAttributeName ] as? UIColor
50+ delimiterLabel. textColor = self . normalTextAttributes [ . foregroundColor ] as? UIColor
5151 }
5252 }
5353
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 )
5757 ] {
5858 didSet {
5959 if isHighlighted { updateTextLabel ( ) }
@@ -64,16 +64,16 @@ class ICToken: UIView {
6464
6565 private( set) lazy var delimiterLabel : UILabel = {
6666 let _label = UILabel ( )
67- _label. textColor = self . normalTextAttributes [ NSForegroundColorAttributeName ] as? UIColor
67+ _label. textColor = self . normalTextAttributes [ . foregroundColor ] as? UIColor
6868 _label. textAlignment = . right
6969 return _label
7070 } ( )
7171
7272 private( set) lazy var textLabel : UILabel = {
7373 let _label = ICInsetLabel ( contentEdgeInsets: UIEdgeInsets ( top: 3 , left: 5 , bottom: 3 , right: 5 ) , cornerRadius: . constant( 3 ) )
7474 _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
7777 _label. numberOfLines = 1
7878 return _label
7979 } ( )
@@ -90,7 +90,12 @@ class ICToken: UIView {
9090 setUpSubviews ( )
9191 }
9292
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+ ) {
9499 self . init ( )
95100 if let attributes = normalAttributes { normalTextAttributes = attributes }
96101 if let attributes = highlightedAttributes { highlightedTextAttributes = attributes }
@@ -105,15 +110,15 @@ class ICToken: UIView {
105110
106111 private func updateTextLabel( ) {
107112 var attributes = isHighlighted ? highlightedTextAttributes : normalTextAttributes
108- if let color = attributes [ NSBackgroundColorAttributeName ] as? UIColor {
113+ if let color = attributes [ . backgroundColor ] as? UIColor {
109114 textLabel. backgroundColor = color
110115 }
111116 // Avoid overlapped translucent background colors
112- attributes [ NSBackgroundColorAttributeName ] = nil
117+ attributes [ . backgroundColor ] = nil
113118 textLabel. attributedText = NSAttributedString ( string: text, attributes: attributes)
114119
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
117122 }
118123
119124 private func setUpSubviews( ) {
0 commit comments