In the previous 'Xcode from scratch for scaredy cats' post I showed you how to create an app without any code at all. This time we're going to modify that app using some actual code. For this you'll need to open the project file from last time: "StaticImage.xcodeproj" (return to point 5 of the previous post if you've forgotten how to view the project files in Xcode).
I'm going to approach this gently and only use one line of code in this entire post. Here's what the line of code looks like:
self.view.backgroundColor = [UIColor yellowColor];
The question is:
What does it do and where does it go?
It changes (or "sets") the background colour of our view to yellow and it goes in the "StaticImageViewController.m" file right beneath the comment "// Do any additional setup after loading the view, typically from a nib."
This comment is inside something called a "method". The method "viewDidLoad" looks like this:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
And with the new code inserted it looks like:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor = [UIColor yellowColor];
}
Once you've inserted this line simply click "Run" the same as you did when following the previous blogpost.
You can change "yellowColor" to "blueColor", "greenColor", among other things and I encourage you to play around. In fact here's a full list of the colours you can choose from to do exactly that:
PRESET COLOURS
blackColor
darkGrayColor
lightGrayColor
whiteColor
grayColor
redColor
greenColor
blueColor
cyanColor
yellowColor
magentaColor
orangeColor
purpleColor
brownColor
clearColor
Now you're comfortable with this try changing the UIColor to "scrollViewTexturedBackgroundColor". It is something called a "system colour".
Here's a full list of "system colours":
SYSTEM COLOURS
lightTextColor
darkTextColor
groupTableViewBackgroundColor
viewFlipsideBackgroundColor
scrollViewTexturedBackgroundColor
underPageBackgroundColor
Each is self-explanatory, and if you've used an iOS device you'll quickly make sense of their intended use.
In the spirit of keeping things simple, that's it for now. Next time we'll be looking at the touch interface and actually having something happen when we touch a button on the screen.
Comments
Post a Comment