Skip to content
This repository was archived by the owner on Aug 24, 2019. It is now read-only.
Open
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
20 changes: 19 additions & 1 deletion SAMTextView/SAMTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,18 @@ - (void)setPlaceholder:(NSString *)string {
if ([string isEqualToString:self.attributedPlaceholder.string]) {
return;
}
if (string == nil) {
self.attributedPlaceholder = nil;
return;
}

NSMutableDictionary *attributes = [[NSMutableDictionary alloc] init];
if ([self isFirstResponder] && self.typingAttributes) {
[attributes addEntriesFromDictionary:self.typingAttributes];
} else {
attributes[NSFontAttributeName] = self.font;
if (self.font) {
attributes[NSFontAttributeName] = self.font;
}
attributes[NSForegroundColorAttributeName] = [UIColor colorWithWhite:0.702f alpha:1.0f];

if (self.textAlignment != NSTextAlignmentLeft) {
Expand Down Expand Up @@ -79,6 +85,18 @@ - (void)setContentInset:(UIEdgeInsets)contentInset {

- (void)setFont:(UIFont *)font {
[super setFont:font];

NSMutableAttributedString *attributedPlaceholder = [self.attributedPlaceholder mutableCopy];
if (attributedPlaceholder) {
NSRange range = NSMakeRange(0, attributedPlaceholder.length);
if (font == nil) {
[attributedPlaceholder removeAttribute:NSFontAttributeName range:range];
} else {
[attributedPlaceholder addAttribute:NSFontAttributeName value:font range:range];
}
self.attributedPlaceholder = attributedPlaceholder;
}

[self setNeedsDisplay];
}

Expand Down