STATIC keyword in Swift - Create custom colors within a UIColor extension.

Max Nelson
A free video tutorial from Max Nelson
Lead iOS Development Engineer
4.0 instructor rating • 11 courses • 29,806 students

Learn more from the full course

iOS Notes App - Advanced Core Data, Navigation, & TableViews

Inject Core Data directly into UITableViews. UINavigationController, UIToolBar, NSLayoutConstraint, NSAttributedString.

04:32:31 of on-demand video • Updated May 2019

  • You will create a professional & well designed navigation hierarchy with UINavigationController, UIViewController & UITableViewController
  • Core Data - Advanced & Basic topics
  • UIToolBar, UINavigationBar, UIBarButtonItem
  • UITableView DataSource & Delegate Protocols
  • UITextView, UILabel, UIButton, UIStackView + StackView Nesting
  • NSAttributedString for complex, customized bodies of text
  • Apple's Human Interface Guidelines.
  • Upload an App to the App Store.
  • NSLayoutConstraint for 100% Programmatic User Interfaces & Layouts (Very clean, fast code.)
English [Auto] Hey there welcome back to the course. You now have a solid understanding of how to create RG B colors from a hex color case. Great job in going through that last video. In this video I'm going to show you how we can create static variables inside of a UI color extension we've written to create a theme inside of our application. Now all we're gonna be doing is basically moving our tint color to the UI color extension and then using it like we would any other UI color. So pretty basic stuff but it's going to give you an understanding to a new approach in swift with UI Colors which will help you in your own IOW apps. So what we want to do is first let's get rid of this viewed our background color inside of our folders controller because we don't really want the background color to be that cyan color. And then now what we need to do is go to our folder notes controller and let's scroll up to our view will appear. Sorry I guess that's in the folders controller. Let's go to our view will appear and you see we have this tint color on our toolbar and navigation bar. What we want to do is say something like primary color instead of DOT cyan. OK so let's head over to our extension and let's write these by saying static var and let's say primary color and let's just set this equal to UI colored on a net. And we're going to choose our hex initialize there and we're just going to say you x e zero B 5 three K. So the E and the zero are the red the B and the ease the green and that five and the three is the blue. Okay. So this is going to initialize us a kind of gold yellow color that you see in the notes app. So let's go ahead and let's head back to our folders controller and let's set this to dot primary color instead of DOT cyan. You can also use something like UI color not primary color just so you understand where it's coming from. It's a UI color now. Right. So we can get rid of that UI color. I just wanted to show you that that's kind of how it works. The reason we can use dye is just cause tint color is expecting a UI color. OK. So that should be it. Let's go ahead and see what it looks like and you'll see now that we have this note's color so feel free to change the primary color to whatever you want. I'm just going to use this gold color because that's what we see in the notes app and that's it. That's how you use static variables inside of an extension for you eye color. I'll see you in the next video.