devxoul / UITextView-Placeholder

A missing placeholder for UITextView
MIT License
1.48k stars 259 forks source link

iOS13 b5 Crashes when setting an attributed placeholder #63

Closed iamcam closed 5 years ago

iamcam commented 5 years ago

When setting an attributed placeholder in iOS13 b5, a crash occurs at dispatch_once in UITextView+Placeholder.m

+ (UIColor *)defaultPlaceholderColor {
    static UIColor *color = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        UITextField *textField = [[UITextField alloc] init];
        textField.placeholder = @" ";
        color = [textField valueForKeyPath:@"_placeholderLabel.textColor"];
    });
    return color;
}

For example, in our Swift code,

let attributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.font: font,
                                                            NSAttributedString.Key.kern: kern,
                                                            NSAttributedString.Key.foregroundColor: Style.placeholderColor]

 textView.attributedPlaceholder = NSAttributedString(string: "Description", attributes: attributes)
fl034 commented 5 years ago

Duplicate of https://github.com/devxoul/UITextView-Placeholder/issues/61

devxoul commented 5 years ago

Fixed in #64