'Capitalized text in UILabel from visual editor in xcode
I am starter in iOS. I found out that there are ways around making the text bold, and changing font and font size etc from visual editor. But are there any ways to set the UILabel text All Capitalized from visual editor (STORYBOARD, NOT CODE). I searched but only found code (Swift/Objective C) based answers like this:
testDisplayLabel.text = testDisplayLabel.text.uppercased()
Solution 1:[1]
A legitimate question -- and a useless (if not arrogant) answer marked as Accepted. It is not unusual when you receive from a copywriter a LOT of text that is not All Caps. So the answer is -- you have to process it all programmatically.
EDIT Generally it is a good idea to wrap your text constants programmatically. First it gives you the opportunity to localize your app (even in the future):
extension String {
func localized (lang: String) -> String {
guard let path = Bundle.main.path (forResource: lang, ofType: "lproj") else { return "" }
guard let bundle = Bundle (path: path) else { return "" }
return NSLocalizedString(self, tableName: nil, bundle: bundle, value: "", comment: "")
}
func localized () -> String {
guard let loc = Locale.current.languageCode else { return "" }
return localized(lang: loc)
}
}
So whenever you need to display a string, you apply this method like this:
"My String".localized()
Likewise, your string should start with a common localisation, and then you make them capitalized when needed:
"This should be all caps".localized().uppercased()
Solution 2:[2]
By default "lowercase word" and "uppercase word" are unbound in Preferences -> Key Bindings -> Text Key Bindings. Just create a new set and bind them to something. Then you will be able to use the binding to capitalize the text.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | ammar shahid |
