devxoul / UITextView-Placeholder

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

Placeholder has wrong font size when UITextView is prepopulated with text #49

Closed mattlogan closed 6 years ago

mattlogan commented 6 years ago

I have a UITextView with font size 22, specified in interface builder. I have the following code in viewDidLoad().

textView.placeHolder = "Placeholder text"
textView.text = "My real text"

The UITextView appears with "My real text" at the correct font size, but when I delete this text to reveal the placeholder, the placeholder font size appears to be 17 (or some smaller default).

devxoul commented 6 years ago

Hmm, can you share your project? It works on my machine. I tested with the demo project.

// ViewController.h
@property (nonatomic, strong) IBOutlet UITextView *textView;

// ViewController.m
- (void)viewDidLoad {
    [super viewDidLoad];
    self.textView.placeholder = @"Placeholder text";
    self.textView.text = @"My real text";
}
screenshot
mattlogan commented 6 years ago

I was able to fix my issue by setting the placeholder text before setting the TextView's text. You can reproduce by changing the above code to:

// ViewController.m
- (void)viewDidLoad {
    [super viewDidLoad];
    self.textView.text = @"My real text";
    self.textView.placeholder = @"Placeholder text";
}

Not sure if this is a bug worth fixing but it might be worth documenting! Thanks for the response.

devxoul commented 6 years ago

I could reproduce the bug with your code. #50 is a patch for the issue. Could you check this? Thanks!

mattlogan commented 6 years ago

I'm not sure this is the right fix. When I apply your patch, I'm now seeing the text overlapping the placeholder view:

screenshot 2018-05-21 10 12 41
devxoul commented 6 years ago

I should have written enough tests... 🤦‍♂️ I have fixed the PR, could you please check it again?

mattlogan commented 6 years ago

This looks good! I verified it in my project.

devxoul commented 6 years ago

Thanks for quick check! I released 1.2.1 to the CocoaPods and it will be available with $ pod update command :tada: