inforeqd
inforeqd

Reputation: 3249

UISearchBar cancel button change language of word 'cancel' in UISearchDisplayController

in iOS5.0 using arc I need to change the word 'cancel' in the cancel button of the UISearchDisplayController to a word derived from the language selected by the user. Since the language is not selected based on localisation, so I cannot just use that. The word comes from a web service. I found a way to do it by walking the subviews in the post below, but is there any other way to do it without assuming apple's view hierarchy?

How can I change strings of "Cancel" button, "No Results" label in UISearchBar of UISearchDisplayController?

Upvotes: 2

Views: 3197

Answers (3)

tounaobun
tounaobun

Reputation: 14857

If you want to localize 'cancel' button's title based on different language in iOS System.You can change the CFBundleDevelopmentRegion key in Info.plist.

<key>CFBundleDevelopmentRegion</key>
<string>en,ru,zh_CN</string> 

Or you can select them in Info.plist file with Xcode Editor.

enter image description here

Here is the Language ID from Apple Doc.

Upvotes: 6

AITAALI_ABDERRAHMANE
AITAALI_ABDERRAHMANE

Reputation: 2519

try this

[[UIButton appearanceWhenContainedIn:[UISearchBar class], nil] 
                                     setTitle:@"button title" 
                                     forState:UIControlStateNormal];

if you want to change hint text

[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] 
                                        setPlaceholder:@"text hint"];

Upvotes: 0

Martin R
Martin R

Reputation: 539815

It seems that you can use the UIAppearance protocol to achieve this:

[[UIButton appearanceWhenContainedIn:[UISearchBar class], nil]
     setTitle:@"Hello world" forState:UIControlStateNormal];

I did only a quick check with the "TableSearch" sample project from Apple, where it worked.

Upvotes: 1

Related Questions