0

However, I've applied different patches still I'm not able to fix placeholder text position and text color for UISearchbar. enter image description here

But when I type something, it's showing up at a proper place.

What's the reason?

Hemang
  • 26,840
  • 19
  • 119
  • 186

2 Answers2

0

This is how you can change the colour of your placeholder text:

UITextField *searchField = [self.searchBar valueForKey:@"searchField"];
searchField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"Some Text"];
UILabel *placeholderLabel = [searchField valueForKey:@"placeholderLabel"];
placeholderLabel.textColor = [UIColor blueColor];

As for the position, by default, placeholder text is vertically centre positioned in the UISearchBar. From your screenshot, it appears to me that there are few new line characters in the end of the text.

Abhinav
  • 37,684
  • 43
  • 191
  • 309
  • Hi Abhinav, thanks, Is this the proper way to achieve this? As I suspect, that, we're using private property to get this done? Would I get AppStore approval for my app with above code? – Hemang Oct 06 '15 at 05:49
  • Your suspicion is correct. It may get rejected by Apple. – Abhinav Oct 06 '15 at 05:50
  • And yes, for the text position, there's no new line character added. Something really go wrong with it. – Hemang Oct 06 '15 at 05:51
  • Oh, then I should not use this as there's a big risk factor exist. Any alternative? I'm not sure what's the problem, as I'm playing with this issue from last many days. Everything is open to me but still I'm not able to solve it. – Hemang Oct 06 '15 at 05:52
0

there's a category created on UITextField, inside it, the placeholder text is drawing. I just corrected the frame and now everything works fine, even that solve the color issue as well.

Hemang
  • 26,840
  • 19
  • 119
  • 186