- Import SwiftFortuneWheel to your ViewController class:
import SwiftFortuneWheel
- Add
UIView
to Storyboard's ViewController. Change class and module toSwiftFortuneWheel
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.
-
WheelView
(configures withSFWConfiguration.WheelPrefereces
) -
SFWConfiguration.AnchorImage
, optional -
SpinButton
(configures withSFWConfiguration.SpinButtonPreferences
) -
PinImageView
(configures withSFWConfiguration.PinImageViewPreferences
). -
Slice
(configures withSlicePreferences
) -
List of
Slice.ContentType
-
Slice.ContentType.image
orSlice.ContentType.assetImage
(configures withImagePreferences
) -
Slice.ContentType.text
(configures withTextPreferences
)
Please note that in order to properly draw objects,
SwiftFortuneWheel
is rellies onSFWConfiguration
. 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.