thieumao

ViewController

Nov 14th, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.41 KB | None | 0 0
  1. import UIKit
  2.  
  3. class ViewController: UIViewController {
  4.    
  5.     // Define identifier
  6.     let notificationName2 = Notification.Name("Did selected language")
  7.    
  8.     var language = [String]()
  9.  
  10.     override func viewDidLoad() {
  11.         super.viewDidLoad()
  12.         language = ["English", "Japanese", "Thái Lan", "Indonesia", "Việt Nam"]
  13.     }
  14.  
  15.     @IBAction func changeLanguage(_ sender: Any) {
  16.         var actionSheet = UIAlertController(title: "Language", message: "Select language", preferredStyle: .actionSheet)
  17.         actionSheet.addAction(UIAlertAction(title: "Huỷ", style: .cancel, handler: {(_ action: UIAlertAction) -> Void in
  18.             // Cancel button tappped.
  19.             self.dismiss(animated: true, completion: {() -> Void in })
  20.         }))
  21.         for item: String in language {
  22.             print("Mao ", item)
  23.             actionSheet.addAction(UIAlertAction(title: item, style: .default, handler: {(_ action: UIAlertAction) -> Void in
  24.                 var langCode = Language.getLanguageCode(item)
  25.                 Language.setLanguage(langCode)
  26.                
  27.                 // Post notification
  28.                 NotificationCenter.default.post(name: BaseUIView.notificationName, object: nil)
  29.                
  30.                 self.dismiss(animated: true, completion: {() -> Void in })
  31.             }))
  32.         }
  33.     self.present(actionSheet, animated: true, completion: { _ in })
  34.     }
  35.    
  36. }
Advertisement
Add Comment
Please, Sign In to add comment