22 Sep 2014

An Objective-C random gradient generator

Using the random color generator presented in a previous post, we can create a random gradient generator for using in our iOS apps.

We can make a class method that take no arguments and returns a 3-color CAGradientLayer, that we could apply as a nice background for our UIView(s) with just one line of code:
[self.view.layer insertSublayer:[ColorUtilities randomGradient] atIndex:0];

An Objective-C random color generator

If you're uncertain about what color to use for an element in your iOS app, a random (nice) color generator maybe might help.

In fact we can use HSB (hue-saturation-lightness) color model to create a random color generator, also limiting the palette to only the nice colours.

An HEX string to UIColor converter

Developing this colourful app for iPad, I found very useful to have a function that takes a HEX color code string as input and returns a properly configured UIColor version of the specified color.

So, for example, you input #FFFDD0 (and a value for alpha transparency), and it returns a UIColor ready for use in the app. That is very handy when trying different palettes in your app or if your app makes use of many colours.

30 May 2014

What's THIS? (In Javascript) - PART II

As promised, here it's the second part of the wondrous journey through the invocation patterns.

What's THIS? (In Javascript) - PART I

In Javascript the value of "this" depends on the invocation pattern used.
In Javascript we have 1 invocation operator (), but 4 invocation patterns.

10 May 2014

Constraints in Points

In iOS Views' coordinates system has its origin in the upper left corner and the units are "points", not pixels. Thus views' positions, sizes and frames are always expressed in points. Working with points allows us to develop code which works fine independently of the screen's pixel density.

12 Apr 2014

Drops of UITableView

For "table-like" structures fans iOS offers UITableView, which is a view object, suitable to display list of items. There's also a UITableViewController that is a UIViewController, so it has a view, but a UIViewController's view is always a UITableView.

5 Mar 2014

The hard life of a View Controller

Just a few notes about the View Controller's lifecycle. The lifecycle is mainly composed of a series of messages that are sent to UIViewController in order to notify it that something "view-related" has just happened or is about to.

2 Feb 2013

Objective-C: messaging to nil

When you call methods in Objective-C you're sending messages (to objects or classes). In many object-oriented languages sending a message to a null pointer crashes your program, in Objective-C it doesn't :)

5 Jan 2013

The Story of How I "uncrustified" My (X)Code

Once upon a time I forgot to align braces and put indents for more code readability. So, how did I quickly tidy it up? Not manually ;)