Maintaining multiple launch screen images for different devices has always been a pain in iOS. Thankfully since iOS8 you can now use a custom view that can automatically adapt to different screen sizes.
In this post I'll show you how to achieve this using RubyMotion.
I'm not a fan of using Xcode for all my views but I think there are a couple of scenarios like this where it is a distinct advantage. In order to use the XCode editor for your RubyMotion project, you'll need to install the
ib gem and run
source 'https://rubygems.org' ... gem 'ib'
Now you can run
rake ib:open which will open your RubyMotion project in Xcode.
Creating a Launch Screen
The first thing we want to do is create a new Launch Screen file.
In Xcode, expand the
ib folder in the left-hand navigator to reveal the Resources directory. This Resources dir maps directly to the
resources folder in your RubyMotion project.
Right click on Resources, choose
New File... and create a new iOS > User Interface > Launch Screen. You can call yours whatever you like, I imaginitively went with
By default Xcode creates a new view that has a label with the name of your project, in this case
ib. I changed the text to
76things in this example. At this point you can start customising the view to suit your needs, for example adding a logo for your app.
All that is now left to do is tell RubyMotion to use this screen as the launch screen.
Motion::Project::App.setup do |app| ... app.info_plist['UILaunchStoryboardName'] = 'LaunchScreen' end
And that's it! You now have a custom view for your launch screen that works nicely for all different screen sizes. If your launch screen is complex you can also take advantage of Auto Layout constraints.
Using a Storyboard
We chose to use a
Launch Screen when creating in Xcode but you can also use a blank
Storyboard to achieve the same result. It requires a bit more work adding a View Controller and I'm not sure what advantage that would bring but it might be useful to know. See the resources below for more information.
Subscribe to 76things
Get the latest posts delivered right to your inbox