How to add a label to a view in Swift
![Oscar de la Hera Gomez](https://www.delasign.com/CDN/headshots/profile.webp)
![A flower that represents Swift next to a flower that represents XCode. Beneath it sits the text that states 'Adding a label to a View in Swift'.](https://www.delasign.com/CDN/images/How-to-add-a-label-to-a-view-in-Swift.webp)
A step by step tutorial on creating a label and adding it to a UIView in Swift (iOS). Github repository included.
The following article walks you through how to create a label and apply content from our LanguageCoordinator. This builds on our existing SwiftLint starter project and the LanguageCoordinator walkthroughs.
Step One: Create your ViewController UI extension
![A screenshot on how to create the ViewController+UI.swift file.](https://www.delasign.com/CDN/images/Create-UI-Extension_2022-07-14-023440_tzhi.webp)
Select the RootViewController folder and press Command + N.
This will select the Swift, iOS file type. Press Next.
After that enter the name of your file - ViewController+UI - and press Create.
Step Two: Create your extension and setup UI function
![A screenshot showing you the code for the new ViewController+UI extension.](https://www.delasign.com/CDN/images/Setup-Extension-and-setupUI.webp)
Copy the code below into your ViewController+UI.swift file.
Step Three: Call your setupUI function
![A screenshot showing you how to call the setupUI function from the ViewController ViewDidLoad function.](https://www.delasign.com/CDN/images/Call-SetupUI.webp)
In your ViewController.swift file, call self.setupUI() from ViewDidLoad.
Step Four: Create your label
![A screenshot showing you how to create a UILabel constant.](https://www.delasign.com/CDN/images/Create-Label-Variable.webp)
Under // MARK: UI create your label as shown above.
Step Five: Add your Label to your view controller
![A screenshot showing you the code we used to add the label to the UIView within the ViewController. Please note we used TinyConstraints to ease our use of Constraints.](https://www.delasign.com/CDN/images/Setup-Label.webp)
In ViewController+UI.swift create a private function called setupLabel and add the label to the view.
In the example code below, we use TinyConstraints to simplify how we layout UI - in this case a label - in our applications.
Step Six: Set your label text
![A screenshot showing you how to update your label text when the content is available.](https://www.delasign.com/CDN/images/Update-Label.webp)
In ViewController.swift update the label text within the LanguageCoordinator.onContentUpdate callback.
Step Seven: Verify
![A screenshot of our app on an iPhone 13.](https://www.delasign.com/CDN/images/Verify1920x1280.webp)
Run your app and verify the text shows up.
Any Questions
We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.