Skip to content

Commit aeb1873

Browse files
authored
Merge pull request #49 from muukii/beta
You released from verbose wrapper API
2 parents b3b823c + e8e8d73 commit aeb1873

File tree

5 files changed

+262
-458
lines changed

5 files changed

+262
-458
lines changed

Demo/ViewController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ class ViewController: UIViewController {
3939

4040
self.growingTextView.layer.cornerRadius = 4
4141
self.growingTextView.backgroundColor = UIColor(white: 0.9, alpha: 1)
42-
self.growingTextView.textContainerInset = UIEdgeInsets(top: 16, left: 0, bottom: 4, right: 0)
42+
self.growingTextView.textView.textContainerInset = UIEdgeInsets(top: 4, left: 0, bottom: 4, right: 0)
4343
self.growingTextView.placeholderAttributedText = NSAttributedString(string: "Placeholder text",
44-
attributes: [NSFontAttributeName: self.growingTextView.font!,
44+
attributes: [NSFontAttributeName: self.growingTextView.textView.font!,
4545
NSForegroundColorAttributeName: UIColor.gray
4646
]
4747
)
@@ -58,7 +58,7 @@ class ViewController: UIViewController {
5858

5959

6060
@IBAction func handleSendButton(_ sender: AnyObject) {
61-
self.growingTextView.text = ""
61+
self.growingTextView.textView.text = ""
6262
self.view.endEditing(true)
6363
}
6464

NextGrowingTextView.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22
s.name = "NextGrowingTextView"
3-
s.version = "0.8.5"
4-
s.summary = "The next in the generations of 'growing textviews' optimized for iOS 7 and above."
3+
s.version = "1.0.0"
4+
s.summary = "The next in the generations of 'growing textviews' optimized for iOS 8 and above."
55
s.homepage = "https://github.com/muukii/NextGrowingTextView"
66
s.license = 'MIT'
77
s.author = { "muukii" => "[email protected]" }

NextGrowingTextView.xcodeproj/project.pbxproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
4BDB87E81DC0423F00E70D5B /* NextGrowingTextView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NextGrowingTextView.h; sourceTree = "<group>"; };
4949
4BDB87E91DC0423F00E70D5B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
5050
4BDB87F01DC0425600E70D5B /* NextGrowingInternalTextView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NextGrowingInternalTextView.swift; sourceTree = "<group>"; };
51-
4BDB87F11DC0425600E70D5B /* NextGrowingTextView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NextGrowingTextView.swift; sourceTree = "<group>"; };
51+
4BDB87F11DC0425600E70D5B /* NextGrowingTextView.swift */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = NextGrowingTextView.swift; sourceTree = "<group>"; tabWidth = 2; };
5252
4BDB87F81DC0426A00E70D5B /* Demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Demo.app; sourceTree = BUILT_PRODUCTS_DIR; };
5353
4BDB87FA1DC0426A00E70D5B /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
5454
4BDB87FC1DC0426A00E70D5B /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
@@ -462,6 +462,7 @@
462462
4BDB87EF1DC0423F00E70D5B /* Release */,
463463
);
464464
defaultConfigurationIsVisible = 0;
465+
defaultConfigurationName = Release;
465466
};
466467
4BDB88071DC0426A00E70D5B /* Build configuration list for PBXNativeTarget "Demo" */ = {
467468
isa = XCConfigurationList;
@@ -470,6 +471,7 @@
470471
4BDB88091DC0426A00E70D5B /* Release */,
471472
);
472473
defaultConfigurationIsVisible = 0;
474+
defaultConfigurationName = Release;
473475
};
474476
/* End XCConfigurationList section */
475477
};

NextGrowingTextView/NextGrowingInternalTextView.swift

Lines changed: 73 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -26,76 +26,82 @@ import UIKit
2626
// MARK: - NextGrowingInternalTextView: UITextView
2727

2828
internal class NextGrowingInternalTextView: UITextView {
29-
30-
// MARK: - Internal
31-
32-
override init(frame: CGRect, textContainer: NSTextContainer?) {
33-
super.init(frame: frame, textContainer: textContainer)
34-
35-
NotificationCenter.default.addObserver(self, selector: #selector(NextGrowingInternalTextView.textDidChangeNotification(_ :)), name: NSNotification.Name.UITextViewTextDidChange, object: self)
36-
}
37-
38-
required init?(coder aDecoder: NSCoder) {
39-
fatalError("init(coder:) has not been implemented")
40-
}
41-
42-
deinit {
43-
NotificationCenter.default.removeObserver(self)
44-
}
45-
46-
override var text: String! {
47-
didSet {
48-
self.updatePlaceholder()
49-
}
50-
}
51-
52-
var placeholderAttributedText: NSAttributedString? {
53-
didSet {
54-
self.setNeedsDisplay()
55-
}
56-
}
57-
58-
override func layoutSubviews() {
59-
super.layoutSubviews()
60-
self.setNeedsDisplay()
61-
}
62-
63-
override func draw(_ rect: CGRect) {
64-
65-
super.draw(rect)
66-
67-
guard self.displayPlaceholder == true else {
68-
return
69-
}
70-
71-
let paragraphStyle: NSMutableParagraphStyle = NSMutableParagraphStyle()
72-
paragraphStyle.alignment = self.textAlignment
73-
74-
let targetRect = CGRect(x: 5 + self.textContainerInset.left,
75-
y: self.textContainerInset.top,
76-
width: self.frame.size.width - (self.textContainerInset.left + self.textContainerInset.right),
77-
height: self.frame.size.height - (self.textContainerInset.top + self.textContainerInset.bottom))
78-
79-
let attributedString = self.placeholderAttributedText
80-
attributedString?.draw(in: targetRect)
29+
30+
// MARK: - Internal
31+
32+
var didChange: () -> Void = {}
33+
34+
override init(frame: CGRect, textContainer: NSTextContainer?) {
35+
super.init(frame: frame, textContainer: textContainer)
36+
37+
NotificationCenter.default.addObserver(self, selector: #selector(NextGrowingInternalTextView.textDidChangeNotification(_ :)), name: NSNotification.Name.UITextViewTextDidChange, object: self)
38+
}
39+
40+
required init?(coder aDecoder: NSCoder) {
41+
fatalError("init(coder:) has not been implemented")
42+
}
43+
44+
deinit {
45+
NotificationCenter.default.removeObserver(self)
46+
}
47+
48+
override var text: String! {
49+
didSet {
50+
didChange()
51+
updatePlaceholder()
8152
}
82-
83-
// MARK: Private
84-
85-
fileprivate var displayPlaceholder: Bool = true {
86-
didSet {
87-
if oldValue != self.displayPlaceholder {
88-
self.setNeedsDisplay()
89-
}
90-
}
53+
}
54+
55+
var placeholderAttributedText: NSAttributedString? {
56+
didSet {
57+
setNeedsDisplay()
9158
}
92-
93-
fileprivate dynamic func textDidChangeNotification(_ notification: Notification) {
94-
95-
self.updatePlaceholder()
59+
}
60+
61+
override func layoutSubviews() {
62+
super.layoutSubviews()
63+
setNeedsDisplay()
64+
}
65+
66+
override func draw(_ rect: CGRect) {
67+
68+
super.draw(rect)
69+
70+
guard displayPlaceholder == true else {
71+
return
9672
}
73+
74+
let paragraphStyle: NSMutableParagraphStyle = NSMutableParagraphStyle()
75+
paragraphStyle.alignment = textAlignment
76+
77+
let targetRect = CGRect(
78+
x: 5 + textContainerInset.left,
79+
y: textContainerInset.top,
80+
width: frame.size.width - (textContainerInset.left + textContainerInset.right),
81+
height: frame.size.height - (textContainerInset.top + textContainerInset.bottom)
82+
)
9783

98-
fileprivate func updatePlaceholder() {
99-
self.displayPlaceholder = self.text.characters.count == 0
84+
let attributedString = placeholderAttributedText
85+
attributedString?.draw(in: targetRect)
86+
}
87+
88+
// MARK: Private
89+
90+
private var displayPlaceholder: Bool = true {
91+
didSet {
92+
if oldValue != displayPlaceholder {
93+
setNeedsDisplay()
94+
}
10095
}
96+
}
97+
98+
private dynamic func textDidChangeNotification(_ notification: Notification) {
99+
100+
updatePlaceholder()
101+
didChange()
102+
}
103+
104+
private func updatePlaceholder() {
105+
displayPlaceholder = text.characters.count == 0
106+
}
101107
}

0 commit comments

Comments
 (0)