{"id":307,"date":"2017-02-15T07:38:53","date_gmt":"2017-02-15T07:38:53","guid":{"rendered":"http:\/\/inwizards.com\/blog\/?p=307"},"modified":"2018-06-19T09:17:27","modified_gmt":"2018-06-19T09:17:27","slug":"set-default-language-textfield-tapping-button-iphone","status":"publish","type":"post","link":"https:\/\/www.inwizards.com\/blog\/set-default-language-textfield-tapping-button-iphone\/","title":{"rendered":"Set Default Language In TextField On Tapping Button In IOS"},"content":{"rendered":"<p><strong>Create a new Project:<\/strong><\/p>\n<p class=\"western\"><span style=\"color: #1d1d1d;\"><span style=\"font-family: Verdana, sans-serif;\"><span style=\"font-size: large;\">-Open Xcode , create a new \u201cSingle Page Application\u201d and select Objective c as the programming language.<\/span><\/span><\/span><\/p>\n<p class=\"western\"><span style=\"color: #777777;\"><span style=\"color: #1d1d1d;\"><span style=\"font-family: Verdana, sans-serif;\"><span style=\"font-size: large;\">-Open the <\/span><\/span><\/span><span style=\"color: #171717;\"><span style=\"font-family: Verdana, sans-serif;\"><span style=\"font-size: large;\">ViewController.h <\/span><\/span><\/span><span style=\"color: #1d1d1d;\"><span style=\"font-family: Verdana, sans-serif;\"><span style=\"font-size: large;\">class and add a new UITextField and NSString instance variable below the class declaration in <\/span><\/span><\/span><span style=\"color: #3f6e74;\"><span style=\"font-family: Verdana, sans-serif;\"><span style=\"font-size: large;\">ViewController.h<\/span><\/span><\/span><span style=\"color: #1d1d1d;\"><span style=\"font-family: Verdana, sans-serif;\"><span style=\"font-size: large;\">.<\/span><\/span><\/span><\/span><\/p>\n<p class=\"western\"><span style=\"color: #777777;\"><span style=\"font-family: Verdana, sans-serif;\"><span style=\"font-size: large;\"><span style=\"color: #aa0d91;\">@property<\/span>(<span style=\"color: #aa0d91;\">nonatomic<\/span>, <span style=\"color: #aa0d91;\">retain<\/span>) <span style=\"color: #5c2699;\">NSString<\/span> *<span style=\"color: #3f6e74;\">str_defaultLang<\/span>;<\/span><\/span><\/span><\/p>\n<p><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<ins class=\"adsbygoogle\"\n     style=\"display:block; text-align:center;\"\n     data-ad-layout=\"in-article\"\n     data-ad-format=\"fluid\"\n     data-ad-client=\"ca-pub-1542270097115731\"\n     data-ad-slot=\"5976953901\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<p class=\"western\"><span style=\"color: #777777;\"><span style=\"font-family: Verdana, sans-serif;\"><span style=\"font-size: large;\"><span style=\"color: #aa0d91;\">@property<\/span>(<span style=\"color: #aa0d91;\">nonatomic<\/span>,<span style=\"color: #aa0d91;\">retain<\/span>) <span style=\"color: #aa0d91;\">IBOutlet<\/span> <span style=\"color: #5c2699;\">UITextField<\/span> *txt_def_lang;<\/span><\/span><\/span><\/p>\n<p class=\"western\"><span style=\"color: #777777;\"><span style=\"font-family: Verdana, sans-serif;\"><span style=\"font-size: large;\">Create method signature on Button in <span style=\"color: #3f6e74;\">ViewController.h<\/span><\/span><\/span><\/span><\/p>\n<p class=\"western\"><span style=\"color: #777777;\"><span style=\"font-family: Verdana, sans-serif;\"><span style=\"font-size: large;\">-(<span style=\"color: #aa0d91;\">IBAction<\/span>)action_language:(<span style=\"color: #aa0d91;\">UIButton*<\/span>)sender;<\/span><\/span><\/span><\/p>\n<p class=\"western\"><span style=\"color: #777777;\"><span style=\"font-family: Verdana, sans-serif;\"><span style=\"font-size: large;\">In StoryBoard<\/span><\/span><\/span><\/p>\n<p class=\"western\" align=\"JUSTIFY\"><span style=\"color: #1d1d1d;\"><span style=\"font-family: Verdana, sans-serif;\"><span style=\"font-size: large;\"><strong>Add a TextField and Button in your Storyboard class<\/strong><\/span><\/span><\/span><\/p>\n<p class=\"western\" align=\"JUSTIFY\"><span style=\"color: #1d1d1d;\"><span style=\"font-family: Verdana, sans-serif;\"><span style=\"font-size: large;\">Search in the component library(It should be in the lower right corner) for TextField and then drag and drop it on the view.<\/span><\/span><\/span><\/p>\n<p class=\"western\" align=\"JUSTIFY\"><span style=\"color: #1d1d1d;\"><span style=\"font-family: Verdana, sans-serif;\"><span style=\"font-size: large;\">Search in the component library(It should be in the lower right corner) for UIButton and then drag and drop it on the view.<\/span><\/span><\/span><\/p>\n<p class=\"western\" align=\"JUSTIFY\"><span style=\"color: #777777;\"><span style=\"font-family: Verdana, sans-serif;\"><span style=\"font-size: large;\"><span style=\"color: #1d1d1d;\">set button title:- \u201c<\/span>Set Default Language<span style=\"color: #1d1d1d;\">\u201d<\/span><\/span><\/span><\/span><\/p>\n<p class=\"western\"><span style=\"color: #1d1d1d;\"><span style=\"font-family: Verdana, sans-serif;\"><span style=\"font-size: large;\"><strong>Connect the Interface Builder Outlets<\/strong><\/span><\/span><\/span><\/p>\n<p class=\"western\"><span style=\"color: #777777;\"><span style=\"font-family: Verdana, sans-serif;\"><span style=\"font-size: large;\">in ViewController.m<\/span><\/span><\/span><\/p>\n<p class=\"western\"><span style=\"color: #777777;\"><span style=\"font-family: Verdana, sans-serif;\"><span style=\"font-size: large;\">First synthesize property in ViewController.m<\/span><\/span><\/span><\/p>\n<p class=\"western\"><span style=\"color: #777777;\"><span style=\"font-family: Verdana, sans-serif;\"><span style=\"font-size: large;\"><span style=\"color: #aa0d91;\">@synthesize<\/span> str_defaultLang,txt_def_lang;<\/span><\/span><\/span><\/p>\n<p class=\"western\"><span style=\"color: #777777;\"><span style=\"font-family: Verdana, sans-serif;\"><span style=\"font-size: large;\">we will write this line in the ViewDidLoad method in ViewController.m:<\/span><\/span><\/span><\/p>\n<p class=\"western\"><span style=\"color: #777777;\"><span style=\"font-family: Verdana, sans-serif;\"><span style=\"font-size: large;\"><span style=\"color: #3f6e74;\">txt_def_lang<\/span>.<span style=\"color: #5c2699;\">userInteractionEnabled<\/span> = <span style=\"color: #aa0d91;\">false<\/span>;<\/span><\/span><\/span><\/p>\n<p class=\"western\"><span style=\"color: #777777;\"><span style=\"font-family: Verdana, sans-serif;\"><span style=\"font-size: large;\">Implement button action method inside ViewController.m:-<\/span><\/span><\/span><\/p>\n<p class=\"western\"><span style=\"color: #777777;\"><span style=\"font-family: Verdana, sans-serif;\"><span style=\"font-size: large;\">-(<span style=\"color: #aa0d91;\">IBAction<\/span>)action_language:(<span style=\"color: #5c2699;\">UIButton<\/span>*)sender{<\/span><\/span><\/span><\/p>\n<p class=\"western\"><span style=\"color: #777777;\"><span style=\"font-family: Verdana, sans-serif;\"><span style=\"font-size: large;\"><span style=\"color: #5c2699;\">NSString<\/span> * languageID = [[<span style=\"color: #5c2699;\">NSLocale<\/span> <span style=\"color: #2e0d6e;\">preferredLanguages<\/span>] <span style=\"color: #2e0d6e;\">objectAtIndex<\/span>:<span style=\"color: #1c00cf;\">0<\/span>];<\/span><\/span><\/span><\/p>\n<p class=\"western\"><span style=\"color: #777777;\"><span style=\"font-family: Verdana, sans-serif;\"><span style=\"font-size: large;\"><span style=\"color: #5c2699;\">NSRange<\/span> range= [[<span style=\"color: #5c2699;\">NSString<\/span> <span style=\"color: #2e0d6e;\">stringWithFormat<\/span>:<span style=\"color: #c41a16;\">@\u201d%@\u201d<\/span>,[[<span style=\"color: #5c2699;\">NSLocale<\/span><span style=\"color: #2e0d6e;\">localeWithLocaleIdentifier<\/span>:languageID]<span style=\"color: #2e0d6e;\">displayNameForKey<\/span>:<span style=\"color: #5c2699;\">NSLocaleIdentifier<\/span><span style=\"color: #2e0d6e;\">value<\/span>:languageID]] <span style=\"color: #2e0d6e;\">rangeOfString<\/span>: <span style=\"color: #c41a16;\">@\u201d \u201c<\/span> <span style=\"color: #2e0d6e;\">options<\/span>:<span style=\"color: #2e0d6e;\">NSBackwardsSearch<\/span>];<\/span><\/span><\/span><\/p>\n<p><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<ins class=\"adsbygoogle\"\n     style=\"display:block; text-align:center;\"\n     data-ad-layout=\"in-article\"\n     data-ad-format=\"fluid\"\n     data-ad-client=\"ca-pub-1542270097115731\"\n     data-ad-slot=\"5976953901\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<p class=\"western\"><span style=\"color: #777777;\"><span style=\"font-family: Verdana, sans-serif;\"><span style=\"font-size: large;\"><span style=\"color: #aa0d91;\">if<\/span> (range.<span style=\"color: #5c2699;\">location<\/span> != <span style=\"color: #5c2699;\">NSNotFound<\/span>) {<\/span><\/span><\/span><\/p>\n<p class=\"western\"><span style=\"color: #777777;\"><span style=\"font-family: Verdana, sans-serif;\"><span style=\"font-size: large;\"><span style=\"color: #3f6e74;\">str_defaultLang<\/span> = [[<span style=\"color: #5c2699;\">NSString<\/span> <span style=\"color: #2e0d6e;\">stringWithFormat<\/span>:<span style=\"color: #c41a16;\">@\u201d%@\u201d<\/span>,[[<span style=\"color: #5c2699;\">NSLocale<\/span><span style=\"color: #2e0d6e;\">localeWithLocaleIdentifier<\/span>:languageID]<span style=\"color: #2e0d6e;\">displayNameForKey<\/span>:<span style=\"color: #5c2699;\">NSLocaleIdentifier<\/span><span style=\"color: #2e0d6e;\">value<\/span>:languageID]] <span style=\"color: #2e0d6e;\">substringToIndex<\/span>: range.<span style=\"color: #5c2699;\">location<\/span>];<\/span><\/span><\/span><\/p>\n<p class=\"western\"><span style=\"color: #777777;\"><span style=\"font-family: Verdana, sans-serif;\"><span style=\"font-size: large;\">} <span style=\"color: #aa0d91;\">else <\/span>{<\/span><\/span><\/span><\/p>\n<p class=\"western\"><span style=\"color: #777777;\"><span style=\"font-family: Verdana, sans-serif;\"><span style=\"font-size: large;\"><span style=\"color: #3f6e74;\">str_defaultLang<\/span> = [<span style=\"color: #5c2699;\">NSString<\/span> <span style=\"color: #2e0d6e;\">stringWithFormat<\/span>:<span style=\"color: #c41a16;\">@\u201d%@\u201d<\/span>,[[<span style=\"color: #5c2699;\">NSLocale<\/span><span style=\"color: #2e0d6e;\">localeWithLocaleIdentifier<\/span>:languageID]<span style=\"color: #2e0d6e;\">displayNameForKey<\/span>:<span style=\"color: #5c2699;\">NSLocaleIdentifier<\/span><span style=\"color: #2e0d6e;\">value<\/span>:languageID]];<\/span><\/span><\/span><\/p>\n<p class=\"western\"><span style=\"color: #777777;\"><span style=\"font-family: Verdana, sans-serif;\"><span style=\"font-size: large;\">}<\/span><\/span><\/span><\/p>\n<p class=\"western\"><span style=\"color: #777777;\"><span style=\"font-family: Verdana, sans-serif;\"><span style=\"font-size: large;\"><span style=\"color: #3f6e74;\">str_defaultLang<\/span> = [<span style=\"color: #5c2699;\">NSString<\/span> <span style=\"color: #2e0d6e;\">stringWithFormat<\/span>:<span style=\"color: #c41a16;\">@\u201d%@\u201d<\/span>,[[<span style=\"color: #3f6e74;\">str_defaultLang<\/span><span style=\"color: #2e0d6e;\">componentsSeparatedByString<\/span>: <span style=\"color: #c41a16;\">@\u201d \u201c<\/span>] <span style=\"color: #2e0d6e;\">objectAtIndex<\/span>:<span style=\"color: #1c00cf;\">0<\/span>]];<\/span><\/span><\/span><\/p>\n<p class=\"western\"><span style=\"color: #777777;\"><span style=\"font-family: Verdana, sans-serif;\"><span style=\"font-size: large;\"><span style=\"color: #3f6e74;\">txt_def_lang<\/span>.<span style=\"color: #5c2699;\">hidden<\/span> = <span style=\"color: #aa0d91;\">false<\/span>;<\/span><\/span><\/span><\/p>\n<p class=\"western\"><span style=\"color: #777777;\"><span style=\"font-family: Verdana, sans-serif;\"><span style=\"font-size: large;\"><span style=\"color: #3f6e74;\">txt_def_lang<\/span>.<span style=\"color: #5c2699;\">text<\/span> = <span style=\"color: #3f6e74;\">str_defaultLang<\/span>;<\/span><\/span><\/span><\/p>\n<p class=\"western\"><span style=\"color: #777777;\"><span style=\"font-family: Verdana, sans-serif;\"><span style=\"font-size: large;\">}<\/span><\/span><\/span><\/p>\n<p><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<ins class=\"adsbygoogle\"\n     style=\"display:block; text-align:center;\"\n     data-ad-layout=\"in-article\"\n     data-ad-format=\"fluid\"\n     data-ad-client=\"ca-pub-1542270097115731\"\n     data-ad-slot=\"5976953901\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<p class=\"western\"><span style=\"color: #000000;\"><span style=\"font-family: Verdana, sans-serif;\"><span style=\"font-size: large;\">and now build and run code.<\/span><\/span><\/span><\/p>\n<p class=\"western\"><span style=\"color: #000000;\"><span style=\"font-family: Verdana, sans-serif;\"><span style=\"font-size: large;\">Tap on button \u201dSet Default Language\u201d show your device default language in textField area<\/span><\/span><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Create a new Project: -Open Xcode , create a new \u201cSingle Page Application\u201d and select Objective c as the programming language. -Open the ViewController.h class and add a new UITextField and NSString instance variable below the class declaration in ViewController.h.<\/p>\n","protected":false},"author":1,"featured_media":310,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"spay_email":""},"categories":[1],"tags":[],"jetpack_featured_media_url":"https:\/\/i2.wp.com\/www.inwizards.com\/blog\/wp-content\/uploads\/2017\/02\/iphone-development-inwizards.jpg?fit=920%2C350&ssl=1","_links":{"self":[{"href":"https:\/\/www.inwizards.com\/blog\/wp-json\/wp\/v2\/posts\/307"}],"collection":[{"href":"https:\/\/www.inwizards.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inwizards.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inwizards.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inwizards.com\/blog\/wp-json\/wp\/v2\/comments?post=307"}],"version-history":[{"count":3,"href":"https:\/\/www.inwizards.com\/blog\/wp-json\/wp\/v2\/posts\/307\/revisions"}],"predecessor-version":[{"id":743,"href":"https:\/\/www.inwizards.com\/blog\/wp-json\/wp\/v2\/posts\/307\/revisions\/743"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.inwizards.com\/blog\/wp-json\/wp\/v2\/media\/310"}],"wp:attachment":[{"href":"https:\/\/www.inwizards.com\/blog\/wp-json\/wp\/v2\/media?parent=307"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inwizards.com\/blog\/wp-json\/wp\/v2\/categories?post=307"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inwizards.com\/blog\/wp-json\/wp\/v2\/tags?post=307"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}