How to create a Radial Gradient in Objective-C (iOS)

Standard

I got bored of working on my PC software project today and decided to dust off my iOS / Objective-C skills again. I’ve not had too many opportunities to sharpen my Objective-C skills and I’m even learning Swift 2 at the moment.

In my PC app, I created a beautiful login screen using a radial-gradient as the background image and I thought: why not recreate something similar using Objective-C. So, I went hunting. StackOverflow and the Apple Developer site led me to the solution below.

To create the radial background, the approach I used was to create a custom UIVew class (obviously, this class extends the UIView class). To do this, from your XCode project, select “File” > “New…” > “File”

Screen Shot 2015-10-27 at 13.58.15

When prompted, select “Cocoa Touch Class” and click “Next”

Screen Shot 2015-10-27 at 13.58.33

Enter the name of your class and make sure that it extends the  UIView  class.

Screen Shot 2015-10-27 at 13.58.33

This done, place the following code in the .m file (the class implementation) for your UIView class.

Make sure to replace  OORadialGradientView  with the name of your own class.

This would give you a class that, by default, adds a radial gradient (from yellow to orange) to any view that it’s attached to. Now, this is all nice and dandy but you won’t see anything yet. To see the effects of your gradient, you need to make use of the class.

Open your storyboard and then do one of two things. Either click directly on the blank space within the default ViewController or, open the Document outline. The document outline button is at the bottom left corner of the Standard Editor. Click this icon and in the Document Outline, select the first “View” element making sure you achieve the following effect:

Screen Shot 2015-10-27 at 14.10.28

This done, move to the identity inspector on the right side of your IDE.

Screen Shot 2015-10-27 at 14.12.24

In the Custom Class field (where “UIView” is written), type in the name of your newly created class. And voila! You’re done.

You can checkout your handiwork by running the project in any simulator of your choice.

Screen Shot 2015-10-27 at 14.15.30

And when rotated in landscape mode:

Screen Shot 2015-10-27 at 14.15.43

Feel free to tweak the numerical values in your Gradient class to adjust the display and colors as you please.

I’ve added this class and would be adding quite a few more to this github project.

 

How to install MySQL and add it as a service on OSX Yosemite

Standard

As I mentioned in a previous post, I’ve just received a new Macbook Air and I continued setting up my development environment. After setting up Apache, I moved on to MySQL and I was a little bit disoriented.

This guide is a note to my future self on how I did it and also to others out there who may be on the verge of getting lost (or worse, frustrated).

I downloaded MySQL Server 5.6 (Community Version) from the MySQL website ( I needed to sign in with my Oracle ID ). After downloading, I ran the installer and MySQL was installed. The README suggests creating aliases for mysql  and mysqladmin . However there are other commands that are helpful such as mysqldump . Instead, I updated my path to include  /usr/local/mysql/bin

You will need to open a new Terminal  window or run the command above for your path to update.

You can start the server and confirm that your MySQL installation is working fine by running this:

But that’s not how you want to setup your database server, is it? Having to start and restart manually anytime you need the database server. You’d want to install it as a service that starts and stops when you startup and shutdown your Macbook.

To install as a service, you can follow this link. In case the information is no longer available, I’ve copied the information below:

OS X uses launch daemons to automatically start, stop, and manage processes and applications such as MySQL. Using launch daemons is recommended over startup items on OS X.

Note

OS X 10.4 deprecated startup items in favour of launchd daemons, and as of OS X 10.10 (Yosemite), startup items do not function. For these reasons, using launchd daemons is preferred over startup items.

Here is an example launchd file that starts MySQL:

Adjust the ProgramArguments array according to your system, as for example your path to mysqld  might be different. After making the proper adjustments, do the following:

  • Save the XML as a file named  /Library/LaunchDaemons/com.mysql.mysql.plist
  • Adjust the file permissions using the Apple recommended owner “root”, owning group “wheel”, and file permissions “644”
  • Enable this new MySQL service

The MySQL daemon is now running, and automatically starts when your system is rebooted.

This is the post that led me on the path to this solution.

How to open hidden folders on OSX finder

Standard

I got a new Macbook Air today and I’ve been setting it up as a development workstation. It’s pretty interesting stuff but also a bit frustrating. I was trying to setup Apache, MySql and PHP but I had issues opening files and folders that are hidden by default on OSX finder.

Luckily for me, I asked Google and I got help.

To open hidden folders such as /etc/apache2 in the Mac OS X Finder, do one of the following:

  • Press Shift + Cmd + G  and type  /etc/apache2
  • Open a Terminal window and type  open /etc/apache2

If you use your Mac as a development machine or just like tinkering around under the hood, you have no doubt been exposed to the folders that are normally hidden from view in the Finder. There are hacks that make the Finder show hidden files and folders, but if you want to keep your Finder windows clutter-free this is a nice way of accessing hidden folders when you need them.