We already have an app running, and we are ready to start creating buttons, labels, and other UI, but first we need to learn how to customize our app: how to set app's icon, how to change splash screens, how to add custom fonts, etc.
All customizations are done in
Rakefile
.
At this moment superapp's
Rakefile.
should look like this:
# -*- coding: utf-8 -*-
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project/template/ios'
begin
require 'bundler'
Bundler.require
rescue LoadError
end
Motion::Project::App.setup do |app|
# Use `rake config' to see complete project settings.
app.name = 'superapp'
end
You can always learn more about
Rakefile
in
Rubymotion's official docs.
First three strings give us access to all Rubymotion commands. Lines
from 6 to 9 give us access to gems that we will include with Bundler.
Block inside
Motion::Project::App.setup
is where we setup the app. Right now only application name is set.
To view all available settings, you can run
rake config
:
Let's add an icon to our app. Because Apple's devices have different screen sizes and resolutions, the app requires multiple icons with different sizes. At this moment, we need three icons, but Apple changes this number sometimes. We need:
Icon-76.png
Icon-60@2x.png
.
Notice
@2x
- it means icon is made for Retina screen, where
1 point equals 2 pixels. Therefore actual image size is 120x120,
but the name says
60
. 60*2 = 120.
Icon-76@2x.png
.
Another Retina icon.
When you have your icons ready, let's put it into
/resources/icons
folder. As you may remember,
/resources
is a folder for all our assets. Icons are one of them, so we are
going to put it there. Since we do not want to make a mess
we will create
/icons
folder, and we will put icons inside:
Now we can tell
Rakefile
where to look for icons. To do it, we need to specify
icons relative paths:
app.icons = [
"icons/Icon-60@2x.png",
"icons/Icon-76.png",
"icons/Icon-76@2x.png"
]
Let's run our app now with
rake
,
and close it in simulator to check the Springboard and our icon with
CMD + Shift + H
:
Splash image is the image that shown when the app is loading. A number of splash screen images depends on a number of devices and screen orientations you support. If you are going to support only iPhones in portrait orientations, four images should be enough:
Default@2x.png
Default-568h@2x.png
Default-667h@2x.png
Default-736h@3x.png
Default-Portrait~ipad.png
Default-Portrait@2x~ipad.png
Default-Landscape~ipad.png
Default-Landscape@2x~ipad.png
You can find some splash images in
/resources
folder already. I think it would be a better idea to create
/resources/splash
folder, and put all splash images inside:
Now we need to tell
Rakefile
where to look for splash images. Unfortunately,
there is no way to tell where
Rubymotion should look for splash images. Rubymotion expects them
to be in the root
of on of the resources folder. Default resources folder, as
you can guess is
/resources
.
However we can add new one:
app.resources_dirs << "resources/splash"
This code adds second Resources folder, and Rubymotion
will look for our splash images in two places now:
/resources
and
/resources/splash
.
Let's start our app, and see whether splash images work now:
You can follow same logic with fonts.
/resources
directory. I would suggest using a subfolder, for example,
/resources/fonts
app.fonts = [
'fonts/FontAwesome.otf'
]
Later we will also use
Rakefile
to specify provisioning profiles and developer certificates for
App Store submitting, adding custom tasks for crash reporting, and
more. But for now, let's learn what App Delegate is and how we can use
it.