Created
March 1, 2020 14:52
-
-
Save LeThinh2511/101e366e9e88478d8c466792c45f8feb to your computer and use it in GitHub Desktop.
UIViewExtension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import UIKit | |
extension UIView { | |
@IBInspectable | |
var localizable: Bool { | |
get { | |
return self.localizable | |
} | |
set { | |
guard newValue else { return } | |
if let label = self as? UILabel { | |
label.text = label.text?.localized() | |
} else if let button = self as? UIButton { | |
let title = button.titleLabel?.text?.localized() | |
button.setTitle(title, for: .normal) | |
} else if let textField = self as? UITextField { | |
textField.text = textField.text?.localized() | |
textField.placeholder = textField.placeholder?.localized() | |
} else if let textView = self as? UITextView { | |
textView.text = textView.text.localized() | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment