Project 8: 7 Swifty Words – Part 1

by | March 18, 2019

Project 8: 7 Swifty Words – Part 1

Jeff Summers

March 18, 2019

Today we began our final game project using UIKit. After this all games will use SpriteKit. In a sense this is kind of sad. It’s like bidding farewell to an old friend that you feel comfortable being around. But like they say, good-byes don’t have to be forever. You can always come back to visit and like all great friendships it’s easy to pick up exactly where you left off.

This project we will be creating a game similar in nature to 7 Little Words. The primary challenge we have in this project is to completely build the user interface programmatically rather than through the Storyboard. I have to admit; I really like Storyboard. It gives me a great visual of what I am trying to accomplish but I can also admit that it sometimes acts as a crutch allowing me to just draw things rather than knowing how it all works.

I understand why we are going through this exercise. We need to know that all things can be done in code. There will be times when it is faster and more time efficient to just write the code rather than drawing it in Storyboard then creating outlets and connecting the pieces. It also gives us some exposure to looking at user interface in code so we can understand what is being built.

Rather than completely describing what the first part of this lesson does, I want to focus on something specific in one of the first steps we did. After creating the variables to hold thinks clues, answers, in-progress answers, player scores, and the buttons for the letters; we then created an override for the function loadView(). This allowed us to create a new instance of a view. We also set the background color to white. It is this last statement I wanted to expand upon.

In the example, there was one simple line that said

view.backgroundColor = .white

This line tells the program to set the background color to white. That works just fine but what if you wanted to change the color? How do you know what color words are appropriate? And what if the color created using the color word is not the exact hue you wanted? Red is not necessarily the red you wanted or were expecting.

Swift has something that I think is kind of cool and makes selecting a color a little easier for you to get the one that is perfect for your application. Let’s change that one line of code above to:

view.backgroundColor = Color Literal

Notice that Color Literal is an auto completion choice. Once you select that and hit enter you will notice that in your Xcode editor you now have a small square of white color. You can double-click that color box and a palette of colors will be displayed which you can choose an appropriate color. If you don’t find one you want, you can select Other… and you are given the Apple Color Picker that you can define whatever color you are looking for.

Once you select the color the color box remains in the editor and you can double-click it at any time to select a different color after seeing how things work. This isn’t the most earth shattering tip but I thought it was kind of cool and something that can be useful if like me you want to keep trying color combinations until you find one that fits in with the aesthetic of the app you are building without trying to figure out color words or hex values.

Share this Article

Posted by Jeff Summers

Author, technologist, and baseball aficionado specializing in information technology and developing new and creative ways to interact with the world around us. My goal is to extend the boundaries of what is possible and find ways to make the world a better place while having fun.

0 Comments

Trackbacks/Pingbacks

  1. Project 8: 7 Swifty Words – Part 2 – Jeff Blogs - […] out the answer to that was no. Oh, it was challenging but not in a finger-numbing way. As with…

Submit a Comment

Your email address will not be published. Required fields are marked *

Stay Connected

Search

More Articles

Pace Layered Architecture Categorization

Change is inevitable. Today’s computing environments are constantly in flux from internal and external forces that put demands on the systems and necessitate changes to maintain its value stream. Technology currency is a constant struggle that organizations must...

TBM, Another Holy Grail?

Technology Business Management or TBM as a term was coined around 2012 although many of the concepts making up this framework have been around for almost as long as there has been IT. In its simplest form, TBM represents the integration of business, technology, and...

Visionary or Dreamer?

Thinking back over your life you’ve met and worked with countless personality types. You have been a part of teams that struggled to complete simple tasks and the work felt meaningless. Perhaps your goal in these times was to just trudge through the mud hoping the...

Archives