Reputation: 33090
Basically I want texts to be smaller (or autoshrink).
I want some part of the texts to have a different color. I like near to be blue with different diminutive font.
How would I do so?
Upvotes: 0
Views: 809
Reputation: 3455
Do you really need to use a UISearchBar
? I had a similar problem and solved it by using a UITextField instead. You can customize the UITextField
to look equal to the UISeachBar
.
The advantage of UITextField
: You can use attributed text! That is a feature available since iOS 6.0 which you even can modify in the text fields attribute inspector. To set the attributed text programmatically use the textField.attributedText property.
You can change the text as you like! Take a look at NSAttributedString. With that you can modify your string as described above.
Upvotes: 3
Reputation: 17409
I guess No, You cant directly decorate text in UISearchBar.
But UISearchBar has a UITextField inside, but there's no property to access it. So, there is no way for doing it in a standard way.But there is a non-stardard way to workaround it. UISearchBar inherits from UIView, you can access it's subviews using [searchBar subviews]. If you print in the console it's subviews you will see that it have these views.
UITextField *textField = [[searchBar subviews] objectAtIndex:1];
for ios7
use this for geting textfiled.
After it using NSAttributedString you can set color or font to textfiled.
Upvotes: 2