A working "class" hero is something to be...

Hello again, and as ever I hope you are all well, and managing to stay sane as the lockdown continues.

This past week has been fully focused on development. As I mentioned in the previous update, building a theme manager had risen to the top of the feature list, and I've spent most of the past week developing this function. "Well OK, but what exactly is a theme manager, Richard?", did I hear someone ask? "And why do you need one at all?" Very well then, let me explain (although be warned, this is going to get technical...)

Like most developers learning to use the Xcode platform for the first time, I've built my first few screens using the Xcode storyboard tool. Prior to version 4, all screens in Xcode had to be built in code, and Objective-C at that, so a fair degree of technical knowledge was required even to build the simplest of apps. Over the years however, Apple has continually enhanced the Xcode toolkit, striving to make it increasingly intuitive and less daunting for new developers.

In 2011, Apple introduced storyboards to Xcode, providing a graphical interface with which to build your app's UI. With storyboards, if you want to add a button to your screen, you can do so by going to the Object Explorer and simply dragging the button to where you want it to appear on your template. What's more, you can change the colour, font, size, behaviour, and all manner of properties for each object directly in the storyboard.

Storyboards in Xcode. To change the colours on the switch, simply set the On Tint and Thumb Tint properties (I took the care to create my own colour themes). Simple - but specific to this switch only.

Sounds great, doesn't it - and indeed, storyboards make the process of building app user interfaces much quicker and simpler. Like most rookie Xcode users, I started out developing my first few screens in storyboard, and configured each screen's buttons, fields and labels individually.This has enabled me to set up the UI quickly, has been a great help in getting the build going.

However, problems are going to arise if I need to make changes across multiple objects. What if I decide I no longer want indigo for the background, or gold for the button text? As I have configured each object individually, I'll need to go through the entire app and update them one-by-one. Painful - and suddenly storyboards aren't quite such a time-saver.

So, before I embark on a big phase of screen creation, I need to make sure I don't store up trouble for myself. Time for a Theme Manager!

One thing I've learned in my time building the app is that Xcode - and Apple - don't provide solutions for every problem you come across in development. Xcode doesn't have a simple "change all colours from A to B" option, mainly because it can't know every scenario your app includes. Instead, it falls to the developer to find the best tool for theming the app's colours and fonts. So I spent time last week trawling the internet for the best option to use.

Example of a custom class. My AppSegmentedControl class is simply a subclass of the base UISegementedControl class.

After a few hours of research (thank heavens for Stack Overflow and Medium in particular), I decided to adopt a solution which uses classes (thanks to this article by Basem Emara for the method). By creating sub-classes of the standard object classes I can implement the specific colours and fonts I want. Now, for labels, instead of having to set each heading's colour and font, I simply use the AppHeading class for the label; for sub-headings I use AppSubHeading, and so on.

The attributes for the Gender segmented control. No need for custom colours here, the class setting does the work.

During the course of this I've had to become familiar with getters, setters, the UIAppearance proxy and Dynamic Type Sizes, and then implement my theme manager across my app, ensuring everything I've built so far works. It's taken a good 3-4 days of effort, but the results are worth it.

A couple of questions I've been asked numerous times in relation to the app are "Why are you developing it yourself? Why don't you just outsource the development?" The theme manager is a great illustration of why I've gone for the hands-on approach. I now have the power to change the app to look exactly how I want it to be, without needing to call upon the services of anyone else, saving me time and money.

Theme Manager at work! Er, this must be the "early 80s New Romantic" theme...

On that note, I've yet to mention the excellent London App Brewery in the blog up until now. None of this would be remotely possible had I not attending their outstanding iOS development course, which I will cover in more detail in the next update.

Finally, some breaking news from the real world - it's just been announced our PM has become a father again, his girlfriend Carrie Symonds having given birth to a baby boy. Congratulations to them both... does this mean he'll take paternity leave now? Another feature to add to the Number Ten backlog...

Thanks for reading, take care and speak soon.


20 views0 comments

Recent Posts

See All