Skip to content
Newer
Older
100644 104 lines (71 sloc) 2.06 KB
0f26b96 @soffes Added TWTextView
soffes authored
1 //
f3d43b6 @soffes The Great Rename
soffes authored
2 // SSTextView.m
3 // SSToolkit
0f26b96 @soffes Added TWTextView
soffes authored
4 //
5 // Created by Sam Soffes on 8/18/10.
e8c3ce3 @soffes Updated comments and renamed SSDrawingMacros to SSDrawingUtilities
soffes authored
6 // Copyright 2010-2011 Sam Soffes. All rights reserved.
0f26b96 @soffes Added TWTextView
soffes authored
7 //
8
f3d43b6 @soffes The Great Rename
soffes authored
9 #import "SSTextView.h"
0f26b96 @soffes Added TWTextView
soffes authored
10
5b58afc @soffes Add `initWithCoder:` to views to allow for use in Interface Builder. …
soffes authored
11 @interface SSTextView ()
12 - (void)_initialize;
0f26b96 @soffes Added TWTextView
soffes authored
13 - (void)_updateShouldDrawPlaceholder;
14 - (void)_textChanged:(NSNotification *)notification;
15 @end
16
17
454e654 @soffes Require Apple LLVM compiler 3.0
soffes authored
18 @implementation SSTextView {
19 BOOL _shouldDrawPlaceholder;
20 }
21
0f26b96 @soffes Added TWTextView
soffes authored
22
bf2d0ec @soffes Started overhauling documentation
soffes authored
23 #pragma mark - Accessors
62be25e @soffes Updated coding style and started on extremitiesStyle
soffes authored
24
0f26b96 @soffes Added TWTextView
soffes authored
25 @synthesize placeholder = _placeholder;
287a788 @soffes Rename `-[SSTextView placeholderColor]` to `-[SSTextView placeholderT…
soffes authored
26 @synthesize placeholderTextColor = _placeholderTextColor;
0f26b96 @soffes Added TWTextView
soffes authored
27
62be25e @soffes Updated coding style and started on extremitiesStyle
soffes authored
28 - (void)setText:(NSString *)string {
29 [super setText:string];
30 [self _updateShouldDrawPlaceholder];
31 }
32
33
34 - (void)setPlaceholder:(NSString *)string {
35 if ([string isEqual:_placeholder]) {
36 return;
37 }
38
c893cb4 @soffes ARC
soffes authored
39 _placeholder = string;
62be25e @soffes Updated coding style and started on extremitiesStyle
soffes authored
40 [self _updateShouldDrawPlaceholder];
41 }
42
43
bf2d0ec @soffes Started overhauling documentation
soffes authored
44 #pragma mark - NSObject
0f26b96 @soffes Added TWTextView
soffes authored
45
46 - (void)dealloc {
47 [[NSNotificationCenter defaultCenter] removeObserver:self name:UITextViewTextDidChangeNotification object:self];
48 }
49
50
bf2d0ec @soffes Started overhauling documentation
soffes authored
51 #pragma mark - UIView
0f26b96 @soffes Added TWTextView
soffes authored
52
5b58afc @soffes Add `initWithCoder:` to views to allow for use in Interface Builder. …
soffes authored
53 - (id)initWithCoder:(NSCoder *)aDecoder {
54 if ((self = [super initWithCoder:aDecoder])) {
55 [self _initialize];
56 }
57 return self;
58 }
59
60
0f26b96 @soffes Added TWTextView
soffes authored
61 - (id)initWithFrame:(CGRect)frame {
f643aac @soffes Switched to LLVM 1.6 and enabled additional warnings. Updated code to…
soffes authored
62 if ((self = [super initWithFrame:frame])) {
5b58afc @soffes Add `initWithCoder:` to views to allow for use in Interface Builder. …
soffes authored
63 [self _initialize];
0f26b96 @soffes Added TWTextView
soffes authored
64 }
65 return self;
66 }
67
68
69 - (void)drawRect:(CGRect)rect {
70 [super drawRect:rect];
71
72 if (_shouldDrawPlaceholder) {
287a788 @soffes Rename `-[SSTextView placeholderColor]` to `-[SSTextView placeholderT…
soffes authored
73 [_placeholderTextColor set];
61f33ab @soffes Revert "Improve SSTextView placeholder alignment"
soffes authored
74 [_placeholder drawInRect:CGRectMake(8.0f, 8.0f, self.frame.size.width - 16.0f, self.frame.size.height - 16.0f) withFont:self.font];
0f26b96 @soffes Added TWTextView
soffes authored
75 }
76 }
77
78
5b58afc @soffes Add `initWithCoder:` to views to allow for use in Interface Builder. …
soffes authored
79 #pragma mark - Private
80
81 - (void)_initialize {
82 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_textChanged:) name:UITextViewTextDidChangeNotification object:self];
83
287a788 @soffes Rename `-[SSTextView placeholderColor]` to `-[SSTextView placeholderT…
soffes authored
84 self.placeholderTextColor = [UIColor colorWithWhite:0.702f alpha:1.0f];
5b58afc @soffes Add `initWithCoder:` to views to allow for use in Interface Builder. …
soffes authored
85 _shouldDrawPlaceholder = NO;
86 }
87
0f26b96 @soffes Added TWTextView
soffes authored
88
89 - (void)_updateShouldDrawPlaceholder {
90 BOOL prev = _shouldDrawPlaceholder;
287a788 @soffes Rename `-[SSTextView placeholderColor]` to `-[SSTextView placeholderT…
soffes authored
91 _shouldDrawPlaceholder = self.placeholder && self.placeholderTextColor && self.text.length == 0;
0f26b96 @soffes Added TWTextView
soffes authored
92
93 if (prev != _shouldDrawPlaceholder) {
94 [self setNeedsDisplay];
95 }
96 }
97
98
0de92a0 @mattbischoff Fixed the spelling of notification in SSTextView.
mattbischoff authored
99 - (void)_textChanged:(NSNotification *)notification {
0f26b96 @soffes Added TWTextView
soffes authored
100 [self _updateShouldDrawPlaceholder];
101 }
102
103 @end
Something went wrong with that request. Please try again.