33// SAMTextView
44//
55// Created by Sam Soffes on 8/18/10.
6- // Copyright 2010-2013 Sam Soffes. All rights reserved.
6+ // Copyright 2010-2014 Sam Soffes. All rights reserved.
77//
88
99#import " SAMTextView.h"
@@ -36,21 +36,21 @@ - (void)setPlaceholder:(NSString *)string {
3636 if ([string isEqualToString: self .attributedPlaceholder.string]) {
3737 return ;
3838 }
39-
39+
4040 NSMutableDictionary *attributes = [[NSMutableDictionary alloc ] init ];
41- if (self.typingAttributes ) {
41+ if ([ self isFirstResponder ] && self.typingAttributes ) {
4242 [attributes addEntriesFromDictionary: self .typingAttributes];
4343 } else {
4444 attributes[NSFontAttributeName ] = self.font ;
4545 attributes[NSForegroundColorAttributeName ] = [UIColor colorWithWhite: 0 .702f alpha: 1 .0f ];
46-
46+
4747 if (self.textAlignment != NSTextAlignmentLeft) {
4848 NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc ] init ];
4949 paragraph.alignment = self.textAlignment ;
5050 attributes[NSParagraphStyleAttributeName ] = paragraph;
5151 }
5252 }
53-
53+
5454 self.attributedPlaceholder = [[NSAttributedString alloc ] initWithString: string attributes: attributes];
5555}
5656
@@ -64,9 +64,9 @@ - (void)setAttributedPlaceholder:(NSAttributedString *)attributedPlaceholder {
6464 if ([_attributedPlaceholder isEqualToAttributedString: attributedPlaceholder]) {
6565 return ;
6666 }
67-
67+
6868 _attributedPlaceholder = attributedPlaceholder;
69-
69+
7070 [self setNeedsDisplay ];
7171}
7272
@@ -140,6 +140,11 @@ - (CGRect)placeholderRectForBounds:(CGRect)bounds {
140140 CGFloat padding = self.textContainer .lineFragmentPadding ;
141141 rect.origin .x += padding;
142142 rect.size .width -= padding * 2 .0f ;
143+ } else {
144+ if (self.contentInset .left == 0 .0f ) {
145+ rect.origin .x += 8 .0f ;
146+ }
147+ rect.origin .y += 8 .0f ;
143148 }
144149
145150 return rect;
0 commit comments