@@ -14,6 +14,7 @@ - (instancetype)initWithFrame:(CGRect)frame {
1414 _placeholderView = [[UILabel alloc ] initWithFrame: self .bounds];
1515 _placeholderView.isAccessibilityElement = NO ;
1616 _placeholderView.numberOfLines = 0 ;
17+ _placeholderView.adjustsFontForContentSizeCategory = YES ;
1718 [self addSubview: _placeholderView];
1819
1920 self.textContainer .lineFragmentPadding = 0 ;
@@ -189,19 +190,31 @@ - (void)setAttributedText:(NSAttributedString *)attributedText {
189190}
190191
191192- (void )setPlaceholderText : (NSString *)newPlaceholderText {
193+ _placeholderText = newPlaceholderText;
194+ [self refreshPlaceholder ];
195+ }
196+
197+ - (void )refreshPlaceholder {
192198 EnrichedTextInputView *typedInput = (EnrichedTextInputView *)_input;
193199 if (typedInput == nullptr ) {
194200 return ;
195201 }
196- _placeholderText = newPlaceholderText;
197- BOOL hasPlaceholder = newPlaceholderText && newPlaceholderText.length > 0 ;
198- NSString *placeholderText = hasPlaceholder ? newPlaceholderText : @" " ;
202+
199203 NSMutableDictionary *attributes =
200204 [typedInput->defaultTypingAttributes mutableCopy ];
201- attributes[NSForegroundColorAttributeName ] = _placeholderColor;
205+
206+ if (_placeholderColor) {
207+ attributes[NSForegroundColorAttributeName ] = _placeholderColor;
208+ }
209+
210+ NSString *placeholder = _placeholderText ?: @" " ;
211+
202212 _placeholderView.attributedText =
203- [[NSAttributedString alloc ] initWithString: placeholderText
213+ [[NSAttributedString alloc ] initWithString: placeholder
204214 attributes: attributes];
215+
216+ [self updatePlaceholderVisibility ];
217+
205218 [self setNeedsLayout ];
206219}
207220
0 commit comments