Capitalized text in UILabel from visual editor in xcode

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 localized 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 capitalization, and then you make them capitalized when needed:

"This should be all caps".localized().uppercased()

Tags:

Ios

Xcode

Uilabel