Skip to content

Latest commit

 

History

History
111 lines (64 loc) · 3.3 KB

GettingStarted.md

File metadata and controls

111 lines (64 loc) · 3.3 KB

Getting Started

How to use

  • Import SwiftFortuneWheel to your ViewController class:
import SwiftFortuneWheel
  • Add UIView to Storyboard's ViewController. Change class and module to SwiftFortuneWheel and @IBOutlet to your ViewController:

Make sure that your SwiftFortuneWheel view has 1:1 aspect ratio.

  • Change basic preferences in you Interface Builder:

For more information, see the API Overview.

/// Fortune Wheel
@IBOutlet weak var fortuneWheel: SwiftFortuneWheel!
  • Create slice content list:
var slices: [Slice] = []
let imagePreferences = ImagePreferences(preferredSize: CGSize(width: 40, height: 40), verticalOffset: 40)
let imageSliceContent = Slice.ContentType.assetImage(name: "crown", preferenes: imagePreferences)
let slice = Slice(contents: [imageSliceContent])
slices.append(slice)

For more information, see the About Slice and Slice’s contents.

  • Create a SwiftFortuneWheel configuration:
let sliceColorType = SFWConfiguration.ColorType.evenOddColors(evenColor: .black, oddColor: .cyan)

let slicePreferences = SFWConfiguration.SlicePreferences(backgroundColorType: sliceColorType, strokeWidth: 1, strokeColor: .black)

let circlePreferences = SFWConfiguration.CirclePreferences(strokeWidth: 10, strokeColor: .black)

let wheelPreferences = SFWConfiguration.WheelPreferences(circlePreferences: circlePreferences, slicePreferences: slicePreferences, startPosition: .bottom)

let configuration = SFWConfiguration(wheelPreferences: wheelPreferences)

For detail information, how to create a configuration object, see the Configuration In-Depth.

  • Pass slices and configuration to the SwiftFortuneWheel:
fortuneWheel.configuration = configuration
fortuneWheel.slices = slices
  • To start spin animation:
fortuneWheel.startRotationAnimation(finishIndex: 0, continuousRotationTime: 1) { (finished) in
            print(finished)
        }

For more information, see the API Overview.


Visual diagram

  1. WheelView (configures with SFWConfiguration.WheelPrefereces)

  2. SFWConfiguration.AnchorImage, optional

  3. SpinButton (configures with SFWConfiguration.SpinButtonPreferences)

  4. PinImageView (configures with SFWConfiguration.PinImageViewPreferences).

  5. Slice (configures with SlicePreferences)

  6. List of Slice.ContentType

  7. Slice.ContentType.image or Slice.ContentType.assetImage (configures with ImagePreferences)

  8. Slice.ContentType.text (configures with TextPreferences)


Necessarily note

Please note that in order to properly draw objects, SwiftFortuneWheel is rellies on SFWConfiguration. It’s up to you how to configure but without configuration, SwiftFortuneWheel won’t work properly.

For detail information, how to create a configuration object, see the Configuration In-Depth.