Skip to content

Commit c0a764b

Browse files
author
Kyle Begeman
committed
Minor tweaks, updated example project.
1 parent 3c0fdf7 commit c0a764b

4 files changed

Lines changed: 51 additions & 63 deletions

File tree

Example/ViewController.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class ViewController: UIViewController, InlineTagControllerDelegate {
1919

2020
tagController.setConfiguration(CustomConfiguration())
2121
tagController.tagDelegate = self
22-
tagController.setPlaceholderText(text: "Enter new tags...")
2322
}
2423

2524
func inlineTagController(_ controller: InlineTagController, didFinishEditing text: String) {
@@ -33,8 +32,17 @@ class ViewController: UIViewController, InlineTagControllerDelegate {
3332
}
3433

3534
class CustomConfiguration: InlineTagConfigurable {
36-
var backgroundColor: ColorCollection = (view: UIColor.black, edit: UIColor.lightGray, invalid: UIColor.blue, placeholder: UIColor.green)
37-
var radius: ValueCollection = (view: 4.0, edit: 0.0, invalid: 8.0)
35+
var backgroundColor: ColorCollection = (view: UIColor.black, edit: UIColor.white, invalid: UIColor.blue, placeholder: UIColor.green)
36+
var radius: ValueCollection = (view: 10.0, edit: 10.0, invalid: 10.0)
3837

39-
var cellHeight: Float = 12.0
38+
39+
var font: FontCollection {
40+
let tagFont = UIFont.systemFont(ofSize: 14.0)
41+
return (view: tagFont, edit: tagFont, invalid: tagFont, placeholder: tagFont)
42+
}
43+
44+
var cellHeight: Float = 20.0
45+
var inset: UIEdgeInsets = UIEdgeInsets(top: 2.0, left: 2.0, bottom: 2.0, right: 2.0)
46+
47+
// Note: Any properties of 'InlineTagConfigurable' not implemented will use default values provided by the framework.
4048
}

InlineTagController.xcodeproj/xcuserdata/kyle.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,19 @@
33
type = "1"
44
version = "2.0">
55
<Breakpoints>
6-
<BreakpointProxy
7-
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
8-
<BreakpointContent
9-
shouldBeEnabled = "Yes"
10-
ignoreCount = "0"
11-
continueAfterRunningActions = "No"
12-
filePath = "Sources/InlineTagConfigurable.swift"
13-
timestampString = "521576595.271164"
14-
startingColumnNumber = "9223372036854775807"
15-
endingColumnNumber = "9223372036854775807"
16-
startingLineNumber = "80"
17-
endingLineNumber = "80"
18-
landmarkName = "set(config:)"
19-
landmarkType = "7">
20-
</BreakpointContent>
21-
</BreakpointProxy>
226
<BreakpointProxy
237
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
248
<BreakpointContent
259
shouldBeEnabled = "Yes"
2610
ignoreCount = "0"
2711
continueAfterRunningActions = "No"
2812
filePath = "Sources/InlineTagController.swift"
29-
timestampString = "521576607.517376"
13+
timestampString = "521582474.518573"
3014
startingColumnNumber = "9223372036854775807"
3115
endingColumnNumber = "9223372036854775807"
32-
startingLineNumber = "104"
33-
endingLineNumber = "104"
34-
landmarkName = "updateForConfig()"
16+
startingLineNumber = "108"
17+
endingLineNumber = "108"
18+
landmarkName = "configure()"
3519
landmarkType = "7">
3620
</BreakpointContent>
3721
</BreakpointProxy>

Sources/InlineTagConfigurable.swift

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@
99
import Foundation
1010
import UIKit
1111

12+
internal class Config {
13+
static let instance = Config()
14+
private init() {
15+
configuration = DefaultConfiguration()
16+
}
17+
18+
var configuration: InlineTagConfigurable
19+
func set(config: InlineTagConfigurable) {
20+
self.configuration = config
21+
}
22+
}
23+
1224
public typealias ColorCollection = (view: UIColor, edit: UIColor, invalid: UIColor, placeholder: UIColor?)
1325
public typealias FontCollection = (view: UIFont, edit: UIFont, invalid: UIFont, placeholder: UIFont)
1426
public typealias ValueCollection = (view: CGFloat, edit: CGFloat, invalid: CGFloat)
@@ -18,6 +30,9 @@ public enum NumberOfTags {
1830
case quantity(Int)
1931
}
2032

33+
public class DefaultConfiguration: InlineTagConfigurable {}
34+
public let TagConfig = Config.instance.configuration
35+
2136
public protocol InlineTagConfigurable {
2237
var backgroundColor: ColorCollection { get }
2338
var fontColor: ColorCollection { get }
@@ -34,6 +49,7 @@ public protocol InlineTagConfigurable {
3449
var autoCorrection: UITextAutocorrectionType { get }
3550
var skipOnWhitespace: Bool { get }
3651
var skipOnReturnKey: Bool { get }
52+
var placeholderText: String { get }
3753
var numberOfTags: NumberOfTags { get }
3854
var itemValidation: Validation? { get }
3955
}
@@ -64,22 +80,7 @@ extension InlineTagConfigurable {
6480
public var autoCorrection: UITextAutocorrectionType { return .no }
6581
public var skipOnWhitespace: Bool { return true }
6682
public var skipOnReturnKey: Bool { return true }
83+
public var placeholderText: String { return "Add tags..." }
6784
public var numberOfTags: NumberOfTags { return .unlimited }
6885
public var itemValidation: Validation? { return InlineTagControllerValidation.testEmptiness }
6986
}
70-
71-
internal class Config {
72-
static let instance = Config()
73-
private init() {
74-
configuration = DefaultConfiguration()
75-
}
76-
77-
var configuration: InlineTagConfigurable
78-
79-
func set(config: InlineTagConfigurable) {
80-
self.configuration = config
81-
}
82-
}
83-
84-
public class DefaultConfiguration: InlineTagConfigurable {}
85-
public let TagConfig = Config.instance.configuration

Sources/InlineTagController.swift

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -61,56 +61,55 @@ public class InlineTagController: UICollectionView {
6161
required public init?(coder aDecoder: NSCoder) {
6262
super.init(coder: aDecoder)
6363
self.collectionViewLayout = InlineTagControllerFlowLayout()
64-
self.customInit()
64+
self.commonInit()
6565
}
6666

6767
override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
6868
super.init(frame: frame, collectionViewLayout: InlineTagControllerFlowLayout())
69-
self.customInit()
69+
self.commonInit()
7070
}
7171

7272
override public var intrinsicContentSize: CGSize {
7373
let size = self.collectionViewLayout.collectionViewContentSize
7474
return CGSize(width: self.bounds.width, height: max(self.minimumHeight(), size.height))
7575
}
7676

77-
public func setConfiguration(_ config: InlineTagConfigurable) {
77+
public func setConfiguration(_ config: InlineTagConfigurable = DefaultConfiguration()) {
7878
Config.instance.set(config: config)
79-
updateForConfig()
79+
configure()
8080
}
8181

82-
private func customInit() {
82+
private func commonInit() {
8383
self.backgroundColor = UIColor.white
84-
var frame = self.bounds
85-
frame.size.height = minimumHeight()
86-
87-
placeholderLabel = UILabel(frame: frame.insetBy(dx: 20, dy: 0))
88-
let view = UIView(frame: frame)
89-
view.addSubview(self.placeholderLabel)
90-
91-
self.backgroundView = view
9284
self.register(InlineTagCell.self, forCellWithReuseIdentifier: InlineTagCell.identifier)
9385

9486
self.dataSource = self
9587
self.delegate = self
9688

9789
self.tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(didTapOnView(_:)))
9890
self.addGestureRecognizer(self.tapRecognizer)
99-
100-
updateForConfig()
10191
}
10292

103-
private func updateForConfig() {
93+
private func configure() {
94+
var frame = self.bounds
95+
frame.size.height = minimumHeight()
96+
97+
placeholderLabel = UILabel(frame: frame.insetBy(dx: 20, dy: 0))
98+
placeholderLabel.font = TagConfig.font.placeholder
99+
placeholderLabel.textColor = TagConfig.fontColor.placeholder
100+
placeholderLabel.text = TagConfig.placeholderText
101+
102+
let view = UIView(frame: frame)
103+
view.addSubview(placeholderLabel)
104+
self.backgroundView = view
105+
104106
sizingCell = InlineTagCell(frame: CGRect(x: 0, y: 0, width: 100, height: CGFloat(TagConfig.cellHeight)))
105107

106108
if let layout = self.collectionViewLayout as? InlineTagControllerFlowLayout {
107109
layout.sectionInset = TagConfig.inset
108110
layout.minimumInteritemSpacing = TagConfig.interitemSpacing
109111
layout.minimumLineSpacing = TagConfig.lineSpacing
110112
}
111-
112-
self.placeholderLabel.font = TagConfig.font.placeholder
113-
self.placeholderLabel.textColor = TagConfig.fontColor.placeholder
114113
}
115114

116115
private func minimumHeight() -> CGFloat {
@@ -196,10 +195,6 @@ public class InlineTagController: UICollectionView {
196195
self.configure(with: tagItems)
197196
}
198197

199-
public func setPlaceholderText(text: String) {
200-
self.placeholderLabel.text = text
201-
}
202-
203198
}
204199

205200
// MARK: - Text manipulation

0 commit comments

Comments
 (0)