Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capitalized text in UILabel from visual editor in xcode

Tags:

xcode

ios

uilabel

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()
like image 324
erluxman Avatar asked Oct 11 '17 06:10

erluxman


People also ask

How do I change my UILabel text?

Changing the text of an existing UILabel can be done by accessing and modifying the text property of the UILabel . This can be done directly using String literals or indirectly using variables.

What is UILabel in Swift?

A view that displays one or more lines of informational text.


1 Answers

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()
like image 137
rommex Avatar answered Oct 15 '22 04:10

rommex