Skip to content
This repository was archived by the owner on Aug 24, 2019. It is now read-only.

Commit beb336a

Browse files
author
Ivan Kovalisko
committed
Merge branch 'master' of github.com:soffes/SAMTextView
2 parents 3e34129 + 99f1dd7 commit beb336a

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2010-2013 Sam Soffes, http://soff.es
1+
Copyright (c) 2010-2014 Sam Soffes, http://soff.es
22

33
Permission is hereby granted, free of charge, to any person obtaining
44
a copy of this software and associated documentation files (the

SAMTextView/SAMTextView.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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 <UIKit/UIKit.h>
@@ -23,7 +23,7 @@
2323

2424
/**
2525
The attributed string that is displayed when there is no other text in the text view.
26-
26+
2727
The default value is `nil`.
2828
*/
2929
@property (nonatomic, strong) NSAttributedString *attributedPlaceholder;

SAMTextView/SAMTextView.m

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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

Comments
 (0)