Although application logic is always the most
important part of an application, the way the interface works plays a
big part in how well it will be received. For Apple and the iPhone,
providing a fun, smooth, and beautiful user experience has been key to
its success; it’s up to you to bring this experience into your own
development. The iPhone SDK’s interface options give you the tools to
express your application’s functionality in fun and unique ways.
This hour introduces two very visual interface features: sliders for input and image views for output.
Sliders
The first new interface component that we’ll be using this hour is a slider (UISlider). Sliders are a convenient touch control that is used to visually set a point within a range of values. Huh? What?
Suppose that you want your
user to be able to speed something up or slow it down. Asking users to
input timing values is unreasonable. Instead, you can present a slider,
as seen in Figure 1, where they can touch and drag an indicator back and forth on a line. Behind the scenes, a value
property is being set that your application can access and use to set
the speed. No need for users to understand the behind-the-scene details
or do anything more than drag with their fingers.
Sliders, like buttons,
can react to events or can be read passively like a text field. If you
want the user’s changes to a slider to immediately have an effect on
your application, you must have it trigger an action.
Image Views
Image views (UIImageView)
do precisely what you’d think: They display images! They can be added
to your application views and used to present information to the user.
An instance of UIImageView can even be
used to create a simple frame-based animation with controls for
starting, stopping, and even setting the speed at which the animation is
shown.
With iOS 4, your image views
can even take advantage of the high-resolution display of the iPhone 4
(and any other upcoming iOS high-resolution devices). Even better, you
need no special coding! Instead of checking for a specific device, you
can just add multiple images to your project, and the image view will
load the right one at the right time.