Download the course materials; this archive contains the presentations, demos, and lab solutions. Please do not distribute these materials outside of your group.
In this lab, you will create a simple tip calculator which you’d then be able to use to split the bill and tip across your friends. You should use the iOS > Application > Single View Application project template in Xcode, because you will only have one screen and one view controller.
Your UI should have the following components:
- A title label that reads “Tip Calculator” – feel free to use a cute font here.
- A text field for the bill amount, and a label that explains what it is.
- A toggle switch that determines whether to round the bill to the nearest dollar, and a label that explains what it is.
- A button that reads “Split Bill”, which, when tapped, calculates the bill amount and tip amount for each person in your party and displays it in a separate label underneath the button.
If you have time, add also the following components:
- A segmented control for choosing the tip %, with allowed values of 10%, 12%, 15%, 18%, and a label that explains what it is.
- A segmented control for choosing the number of people to split the bill across, with allowed values of 1, 2, 3, 4, 5, and a label that explains what it is.
NOTE: Remember that you will need to use the resignFirstResponder
trick on the UITextField
so that the keyboard goes away when the user taps the Return key. If you get stuck, review the demo code for Module 2 in the course materials (under the DemoCode folder).
NOTE: Although it’s tempting, do not use a numeric/decimal keyboard type. If you do, the textFieldShouldReturn:
protocol method will not be invoked because there is no “Done” button on the numeric keyboard. To get the text field to resign its first responder status in that case, you would have to introduce a Tap Gesture Recognizer that would detect taps outside the fields (in the background area) and then cause the text field to resign its first responder status. We don’t recommend that you go in this direction yet, unless you have extra time.