Skip to content
This repository was archived by the owner on Aug 24, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion SAMTextView/SAMTextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,15 @@
@property (nonatomic, strong) NSAttributedString *attributedPlaceholder;

/**
Returns the drawing rectangle for the text views’s placeholder text.
The attributes for the string that is displayed when there is no other text in the text view.

The default value is `nil`.
*/
@property (nonatomic, strong) NSDictionary *placeholderTextAttributes UI_APPEARANCE_SELECTOR;

/**
Returns the drawing rectangle for the text views’s placeholder text.

@param bounds The bounding rectangle of the receiver.
@return The computed drawing rectangle for the placeholder text.
*/
Expand Down
13 changes: 12 additions & 1 deletion SAMTextView/SAMTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ - (void)setPlaceholder:(NSString *)string {
}

NSMutableDictionary *attributes = [[NSMutableDictionary alloc] init];
if (self.typingAttributes) {
if (self.placeholderTextAttributes) {
[attributes addEntriesFromDictionary:self.placeholderTextAttributes];
} else if (self.typingAttributes) {
[attributes addEntriesFromDictionary:self.typingAttributes];
} else {
attributes[NSFontAttributeName] = self.font;
Expand Down Expand Up @@ -70,6 +72,15 @@ - (void)setAttributedPlaceholder:(NSAttributedString *)attributedPlaceholder {
[self setNeedsDisplay];
}

- (void)setPlaceholderTextAttributes:(NSDictionary *)placeholderTextAttributes {
if ([placeholderTextAttributes isEqualToDictionary:_placeholderTextAttributes]) {
return;
}

_placeholderTextAttributes = placeholderTextAttributes;

self.attributedPlaceholder = [[NSAttributedString alloc] initWithString:self.attributedPlaceholder.string attributes:_placeholderTextAttributes];
}

- (void)setContentInset:(UIEdgeInsets)contentInset {
[super setContentInset:contentInset];
Expand Down