Skip to content

Commit 803e7cb

Browse files
committed
Fix crash when attributed placeholder has length 0
1 parent c9f587a commit 803e7cb

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

MaterialTextField/MFTextField.m

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,14 @@ - (void)updatePlaceholderColor
498498

499499
- (NSAttributedString *)attributedString:(NSAttributedString *)attributedString withColor:(UIColor *)color
500500
{
501-
NSMutableDictionary *attributes = [[attributedString attributesAtIndex:0 effectiveRange:NULL] mutableCopy];
501+
NSMutableDictionary *attributes;
502+
503+
if (attributedString.length > 0) {
504+
attributes = [[attributedString attributesAtIndex:0 effectiveRange:NULL] mutableCopy];
505+
}
506+
else {
507+
attributes = [NSMutableDictionary dictionary];
508+
}
502509
attributes[NSForegroundColorAttributeName] = color;
503510

504511
return [[NSAttributedString alloc] initWithString:attributedString.string attributes:attributes];

0 commit comments

Comments
 (0)