简体   繁体   English

UISearchBar占位符文本颜色/位置

[英]UISearchBar placeholder text color/location

However, I've applied different patches still I'm not able to fix placeholder text position and text color for UISearchbar . 但是,我已经应用了不同的补丁,但仍无法为UISearchbar修复占位符的文本位置和文本颜色。 在此处输入图片说明

But when I type something, it's showing up at a proper place. 但是,当我键入内容时,它会显示在适当的位置。

What's the reason? 什么原因?

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 . 至于位置,默认情况下,占位符文本在UISearchBar垂直居中。 From your screenshot, it appears to me that there are few new line characters in the end of the text. 从您的屏幕截图来看,在我看来,文本末尾几乎没有换行符。

there's a category created on UITextField , inside it, the placeholder text is drawing. UITextField创建了一个类别,其中的占位符文本正在绘制。 I just corrected the frame and now everything works fine, even that solve the color issue as well. 我刚刚校正了框架,现在一切正常,即使也解决了颜色问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM