Skip to content

Instantly share code, notes, and snippets.

@LeThinh2511
Created March 1, 2020 14:52
Show Gist options
  • Save LeThinh2511/101e366e9e88478d8c466792c45f8feb to your computer and use it in GitHub Desktop.
Save LeThinh2511/101e366e9e88478d8c466792c45f8feb to your computer and use it in GitHub Desktop.
UIViewExtension
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