Skip to content

Commit 4495c51

Browse files
committed
Customize text color and tint color of ICTokenField using storyboard
1 parent 750681c commit 4495c51

3 files changed

Lines changed: 66 additions & 3 deletions

File tree

Example/Example/Main.storyboard

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,31 @@
6060
<rect key="frame" x="0.0" y="0.0" width="600" height="43.5"/>
6161
<autoresizingMask key="autoresizingMask"/>
6262
<subviews>
63-
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="2dP-7v-mWC" customClass="ICTokenField" customModule="ICInputAccessory">
64-
<rect key="frame" x="0.0" y="0.0" width="600" height="43.5"/>
63+
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="2dP-7v-mWC" customClass="ICTokenField" customModule="ICInputAccessory">
64+
<rect key="frame" x="0.0" y="0.0" width="600" height="44"/>
6565
<color key="backgroundColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
66+
<color key="tintColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
6667
<userDefinedRuntimeAttributes>
6768
<userDefinedRuntimeAttribute type="string" keyPath="placeholder" value="ICTokenFIeld"/>
6869
<userDefinedRuntimeAttribute type="image" keyPath="icon" value="icook-iphone-input-search"/>
6970
<userDefinedRuntimeAttribute type="number" keyPath="cornerRadius">
70-
<real key="value" value="5"/>
71+
<real key="value" value="0.0"/>
7172
</userDefinedRuntimeAttribute>
7273
<userDefinedRuntimeAttribute type="number" keyPath="borderWidth">
7374
<real key="value" value="0.0"/>
7475
</userDefinedRuntimeAttribute>
76+
<userDefinedRuntimeAttribute type="color" keyPath="textColor">
77+
<color key="value" white="1" alpha="1" colorSpace="calibratedWhite"/>
78+
</userDefinedRuntimeAttribute>
7579
</userDefinedRuntimeAttributes>
7680
</view>
7781
</subviews>
82+
<constraints>
83+
<constraint firstItem="2dP-7v-mWC" firstAttribute="centerY" secondItem="6tu-Im-VHX" secondAttribute="centerY" id="QVu-go-I6O"/>
84+
<constraint firstItem="2dP-7v-mWC" firstAttribute="leading" secondItem="6tu-Im-VHX" secondAttribute="leading" id="UjO-GY-bMj"/>
85+
<constraint firstAttribute="trailing" secondItem="2dP-7v-mWC" secondAttribute="trailing" id="qHK-Hg-C1s"/>
86+
<constraint firstItem="2dP-7v-mWC" firstAttribute="top" secondItem="6tu-Im-VHX" secondAttribute="top" id="tCI-Eg-VzE"/>
87+
</constraints>
7888
</tableViewCellContentView>
7989
</tableViewCell>
8090
</cells>
@@ -86,6 +96,9 @@
8696
</connections>
8797
</tableView>
8898
<navigationItem key="navigationItem" title="ICInputAccessory" id="Q3g-An-b4N"/>
99+
<connections>
100+
<outlet property="tokenField" destination="2dP-7v-mWC" id="iiG-b9-QDf"/>
101+
</connections>
89102
</tableViewController>
90103
<placeholder placeholderIdentifier="IBFirstResponder" id="4Lj-fL-J07" userLabel="First Responder" sceneMemberID="firstResponder"/>
91104
<view contentMode="scaleToFill" id="zaj-ho-SsM" customClass="ICKeyboardDismissAccessoryView" customModule="ICInputAccessory">

Example/Example/StoryboardViewController.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,24 @@
2525
//
2626

2727
import UIKit
28+
import ICInputAccessory
2829

2930
class StoryboardViewController: UITableViewController {
3031

32+
@IBOutlet weak var tokenField: ICTokenField! {
33+
didSet {
34+
tokenField.normalTokenAttributes = [
35+
NSForegroundColorAttributeName: UIColor.whiteColor(),
36+
NSBackgroundColorAttributeName: UIColor.whiteColor().colorWithAlphaComponent(0.25),
37+
]
38+
39+
tokenField.highlightedTokenAttributes = [
40+
NSForegroundColorAttributeName: UIColor.darkGrayColor(),
41+
NSBackgroundColorAttributeName: UIColor.whiteColor(),
42+
]
43+
}
44+
}
45+
3146
@IBAction func dismiss(sender: UIButton) {
3247
presentingViewController?.dismissViewControllerAnimated(true, completion: nil)
3348
}

Source/ICTokenField.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ import UIKit
4747
@IBDesignable
4848
public class ICTokenField: UIView, UITextFieldDelegate, ICBackspaceTextFieldDelegate {
4949

50+
// MARK: - Public Properties
51+
5052
/// The receiver’s delegate.
5153
public weak var delegate: ICTokenFieldDelegate?
5254

@@ -129,6 +131,35 @@ public class ICTokenField: UIView, UITextFieldDelegate, ICBackspaceTextFieldDele
129131
}
130132
}
131133

134+
/// The tint color of icon image and text field.
135+
public override var tintColor: UIColor! {
136+
didSet {
137+
inputTextField.tintColor = tintColor
138+
leftView?.tintColor = tintColor
139+
}
140+
}
141+
142+
/// The text color of text field in the interface builder. Same as textField.text.
143+
@IBInspectable var textColor: UIColor? {
144+
get {
145+
return inputTextField.textColor
146+
}
147+
set {
148+
inputTextField.textColor = newValue
149+
}
150+
}
151+
152+
/// The corner radius of token field in the interface builder. Same as layer.cornerRadius.
153+
@IBInspectable var cornerRadius: CGFloat {
154+
get {
155+
return layer.cornerRadius
156+
}
157+
set {
158+
layer.cornerRadius = newValue
159+
layer.masksToBounds = newValue > 0
160+
}
161+
}
162+
132163
// MARK: - Private Properties
133164

134165
private var tokens = [ICToken]()
@@ -220,6 +251,10 @@ public class ICTokenField: UIView, UITextFieldDelegate, ICBackspaceTextFieldDele
220251
icon = image
221252
case let text as String? where key == "placeholder":
222253
placeholder = text
254+
case let color as UIColor? where key == "textColor":
255+
textColor = color
256+
case let value as CGFloat where key == "cornerRadius":
257+
cornerRadius = value
223258
default:
224259
break
225260
}

0 commit comments

Comments
 (0)