Code Monkey home page Code Monkey logo

swift-pickinfruit-lab-ios-0616's Introduction

Pickin Fruit

Fruit

Objectives

  • Create a fruity slot game using UIPickerView, UIPickerViewDelegate, and UIPickerViewDataSource

Introduction

In this lab you will use UIPickerView to make a slot game called, 'Pickin Fruit'. Each component in our picker view will represent a reel of fruit within our slot machine. UIPickerView is similar to a UITableView in that it requires adopting a delegate and a data source. These adoptions are necessary to provide the picker view with the data it needs to construct itself. Check out Apple's documentation about UIPickerView, UIPickerViewDelegate, and UIPickerViewDataSource. Your storyboard is already set up with a picker view, a results label, and a spin button. The outlets for the label and the button are already included in your ViewController class, along with an IBAction for the button. Your ViewController class has an instance property array that contains the fruit (data).

1. Implement the necessary protocols on the picker view


  • Control drag to create an outlet property for your picker view called fruitPicker (Be sure to uncomment the accessibility label declaration for fruitPicker in viewDidLoad()).
  • Implement the 2 necessary data source delegate methods to provide data to the picker view. The picker view should have 3 components.
  • Implement the pickerView(_:titleForRow:forComponent:) to set each fruit string from the array to the row title.

2. Handle winning and losing scenarios


  • Inside the spinButton IBAction method, use selectRow(_:inComponent:animated:) and selectedRow(inComponent:) to spin the picker and process the outcome.
  • Update the text value on resultLabel with "TRY AGAIN" or "WINNER!" depending on the outcome of the spin.
  • Run the test.

Advanced

  • It's not possible to know the duration of the picker view animation because Apple keeps the functionality private. However, it's approximately 0.3 seconds. Play around with the the label's alpha, along with delay and options on animate(withDuration:delay:options:animations:completion:). Try to delay the appearance of the label and make it blink a couple of times before disappearing.
  • Manipulate the count for the UIPickerViewDataSource to be greater than the array in order to make the spin appear more slot-machine-like. You can also start the picker view at different positions so the fruit will cover the view top to bottom.

swift-pickinfruit-lab-ios-0616's People

Contributors

joelconnects avatar imryan avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.