Skip to content

Commit

Permalink
0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-khashimov committed Jun 18, 2020
1 parent 9654382 commit 8f70611
Show file tree
Hide file tree
Showing 13 changed files with 235 additions and 47 deletions.
11 changes: 11 additions & 0 deletions Documentation/Changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## CHANGELOG

### v0.6.0
- added `line` to `Slice.ContentType` and `LinePreferences`. Now supports a curved line inside a slice;
- Optional `backgroundColor` added to `Slice`. You can now override a background color for specified `Slice`, during `Slice` initialization;
- Optional `centerImageAnchor` added to `WheelPreferences`. You can now add a secondary anchor image for each slice that will be located at the center of wheel’s border;
- Examples updated;

### v0.5.0

First public release
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="5" translatesAutoresizingMaskIntoConstraints="NO" id="hKR-QZ-bJF">
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="hKR-QZ-bJF">
<rect key="frame" x="10" y="103" width="394" height="744"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="kck-RA-QdL">
Expand All @@ -90,16 +90,16 @@
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="13H-a0-QhX">
<rect key="frame" x="0.0" y="45" width="394" height="60"/>
<rect key="frame" x="0.0" y="40" width="394" height="60"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" alignment="center" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="J32-LM-JsG">
<rect key="frame" x="78" y="10" width="238" height="40"/>
<rect key="frame" x="79" y="10" width="236" height="40"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="7bf-R4-Lzx">
<rect key="frame" x="0.0" y="6" width="114" height="28"/>
<rect key="frame" x="0.0" y="6" width="113" height="28"/>
<color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<inset key="contentEdgeInsets" minX="10" minY="5" maxX="10" maxY="5"/>
<state key="normal" title="Add Price">
<state key="normal" title="Add Prize">
<color key="titleColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</state>
<userDefinedRuntimeAttributes>
Expand All @@ -108,14 +108,14 @@
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
<connections>
<action selector="addPriceAction:" destination="uOf-zF-lNR" eventType="touchUpInside" id="JQ3-xS-I36"/>
<action selector="addPrizeAction:" destination="uOf-zF-lNR" eventType="touchUpInside" id="JQ3-xS-I36"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="veH-1V-PQe">
<rect key="frame" x="124" y="6" width="114" height="28"/>
<rect key="frame" x="123" y="6" width="113" height="28"/>
<color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<inset key="contentEdgeInsets" minX="10" minY="5" maxX="10" maxY="5"/>
<state key="normal" title="Remove Price">
<state key="normal" title="Remove Prize">
<color key="titleColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</state>
<userDefinedRuntimeAttributes>
Expand All @@ -124,7 +124,7 @@
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
<connections>
<action selector="removePriceAction:" destination="uOf-zF-lNR" eventType="touchUpInside" id="BAO-nZ-5sN"/>
<action selector="removePrizeAction:" destination="uOf-zF-lNR" eventType="touchUpInside" id="BAO-nZ-5sN"/>
</connections>
</button>
</subviews>
Expand All @@ -139,7 +139,7 @@
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="1tF-2P-yEk">
<rect key="frame" x="0.0" y="110" width="394" height="40"/>
<rect key="frame" x="0.0" y="100" width="394" height="40"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" alignment="center" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="UUV-nP-POx">
<rect key="frame" x="62.5" y="0.0" width="269" height="40"/>
Expand Down Expand Up @@ -172,8 +172,40 @@
<constraint firstItem="UUV-nP-POx" firstAttribute="centerX" secondItem="1tF-2P-yEk" secondAttribute="centerX" id="nkS-FT-uIL"/>
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="8Zp-6b-udk">
<rect key="frame" x="0.0" y="140" width="394" height="40"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" alignment="center" spacing="15" translatesAutoresizingMaskIntoConstraints="NO" id="4YP-0W-Cjm">
<rect key="frame" x="65" y="0.0" width="264" height="40"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Draw curved line:" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="FPm-84-pqL">
<rect key="frame" x="0.0" y="10" width="200" height="20.5"/>
<constraints>
<constraint firstAttribute="width" constant="200" id="ceq-Ia-Z8X"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="mrM-IU-qDK">
<rect key="frame" x="215" y="4.5" width="51" height="31"/>
<connections>
<action selector="drawCurverLineSwitchChanged:" destination="uOf-zF-lNR" eventType="valueChanged" id="4D3-rS-qu9"/>
</connections>
</switch>
</subviews>
</stackView>
</subviews>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<constraints>
<constraint firstItem="4YP-0W-Cjm" firstAttribute="top" secondItem="8Zp-6b-udk" secondAttribute="top" id="HnQ-dH-9vi"/>
<constraint firstItem="4YP-0W-Cjm" firstAttribute="centerX" secondItem="8Zp-6b-udk" secondAttribute="centerX" id="ON6-Lc-cyk"/>
<constraint firstAttribute="bottom" secondItem="4YP-0W-Cjm" secondAttribute="bottom" id="Ue7-gy-pdl"/>
<constraint firstAttribute="height" constant="40" id="dab-Tb-jOb"/>
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="sdz-4n-Q3b">
<rect key="frame" x="0.0" y="155" width="394" height="414"/>
<rect key="frame" x="0.0" y="180" width="394" height="414"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Wrs-PJ-1Pe" customClass="SwiftFortuneWheel" customModule="SwiftFortuneWheel">
<rect key="frame" x="0.0" y="10" width="394" height="394"/>
Expand All @@ -195,7 +227,7 @@
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="cZ2-7a-0DG">
<rect key="frame" x="0.0" y="574" width="394" height="170"/>
<rect key="frame" x="0.0" y="594" width="394" height="150"/>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
</view>
</subviews>
Expand All @@ -213,6 +245,7 @@
<navigationItem key="navigationItem" id="cAS-1j-A7G"/>
<connections>
<outlet property="colorsTypeSegment" destination="tVp-MG-bzR" id="z7v-vh-Nbg"/>
<outlet property="drawCurvedLineSwitch" destination="mrM-IU-qDK" id="AkJ-3f-PQc"/>
<outlet property="fortuneWheel" destination="Wrs-PJ-1Pe" id="Moc-ND-yHC"/>
<outlet property="keyboardToolbar" destination="sar-cH-9sz" id="rHt-lP-Qjk"/>
<outlet property="selectedIndexTextField" destination="JiW-tK-GjQ" id="4Xd-zw-xr7"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import SwiftFortuneWheel

class ExampleViewController: UIViewController {

@IBOutlet weak var drawCurvedLineSwitch: UISwitch!
@IBOutlet weak var colorsTypeSegment: UISegmentedControl!

@IBOutlet weak var fortuneWheel: SwiftFortuneWheel! {
Expand All @@ -25,6 +26,12 @@ class ExampleViewController: UIViewController {

var prizes: [Prize] = []

var drawCurvedLine: Bool = false {
didSet {
updateSlices()
}
}

var minimumPrize: Int {
return 4
}
Expand All @@ -50,6 +57,8 @@ class ExampleViewController: UIViewController {

selectedIndexTextField.inputAccessoryView = keyboardToolbar

drawCurvedLine = drawCurvedLineSwitch.isOn

prizes.append(Prize(amount: 100, description: "Prize".uppercased(), priceType: .money))
prizes.append(Prize(amount: 200, description: "Prize".uppercased(), priceType: .money))
prizes.append(Prize(amount: 300, description: "Prize".uppercased(), priceType: .money))
Expand All @@ -70,21 +79,25 @@ class ExampleViewController: UIViewController {
updateSlices()
}

@IBAction func addPriceAction(_ sender: Any) {
@IBAction func addPrizeAction(_ sender: Any) {
guard prizes.count < maximumPrize - 1 else { return }
let price = Prize(amount: (prizes.count + 1) * 100, description: "Prize".uppercased(), priceType: .money)
prizes.append(price)

updateSlices()
}

@IBAction func removePriceAction(_ sender: Any) {
@IBAction func removePrizeAction(_ sender: Any) {
guard prizes.count > minimumPrize else { return }
_ = prizes.popLast()

updateSlices()
}

@IBAction func drawCurverLineSwitchChanged(_ sender: UISwitch) {
drawCurvedLine = sender.isOn
}

@IBAction func selectedIndexValueChange(_ sender: Any) {
selectedIndexTextField.text = "\(finishIndex)"
}
Expand All @@ -95,13 +108,18 @@ class ExampleViewController: UIViewController {


func updateSlices() {
let slices: [Slice] = prizes.map({ Slice(contents: $0.sliceContentTypes(isMonotone: colorsTypeSegment.selectedSegmentIndex == 1)) })
let slices: [Slice] = prizes.map({ Slice(contents: $0.sliceContentTypes(isMonotone: colorsTypeSegment.selectedSegmentIndex == 1, withLine: drawCurvedLine)) })

fortuneWheel.slices = slices

if prizes.count == maximumPrize - 1 {
let imageSliceContent = Slice.ContentType.image(name: "crown", preferenes: ImagePreferences(preferredSize: CGSize(width: 40, height: 40), verticalOffset: 40))
let slice = Slice(contents: [imageSliceContent])
var slice = Slice(contents: [imageSliceContent])
if drawCurvedLine {
let linePreferences = LinePreferences(colorType: .customPatternColors(colors: nil, defaultColor: .black), height: 2, verticalOffset: 35)
let line = Slice.ContentType.line(preferenes: linePreferences)
slice.contents.append(line)
}
fortuneWheel.slices.append(slice)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ extension Prize {
return [Slice.ContentType.text(text: amountFormatted, preferenes: .amountTextWithWhiteBlackColorsPreferences), Slice.ContentType.text(text: description, preferenes: .descriptionTextWithWhiteBlackColorsPreferences), Slice.ContentType.image(name: priceType.imageName, preferenes: .prizeImagePreferences)]
}

func sliceContentTypes(isMonotone: Bool) -> [Slice.ContentType] {
return [Slice.ContentType.text(text: amountFormatted, preferenes: isMonotone ? .amountTextWithBlackColorPreferences : .amountTextWithWhiteBlackColorsPreferences),
Slice.ContentType.text(text: description, preferenes: isMonotone ? .descriptionTextWhiteBlackColorPreferences : .descriptionTextWithWhiteBlackColorsPreferences),
Slice.ContentType.image(name: priceType.imageName, preferenes: .prizeImagePreferences)]
func sliceContentTypes(isMonotone: Bool, withLine: Bool = false) -> [Slice.ContentType] {
var sliceContentTypes = [Slice.ContentType.text(text: amountFormatted, preferenes: isMonotone ? .amountTextWithBlackColorPreferences : .amountTextWithWhiteBlackColorsPreferences),
Slice.ContentType.text(text: description, preferenes: isMonotone ? .descriptionTextWhiteBlackColorPreferences : .descriptionTextWithWhiteBlackColorsPreferences),
Slice.ContentType.image(name: priceType.imageName, preferenes: .prizeImagePreferences)]
if withLine {
sliceContentTypes.append(Slice.ContentType.line(preferenes: .defaultPreferences))
}
return sliceContentTypes
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ extension SwiftFortuneWheelConfiguration.WheelPreferences {
}

static var exampleRainbowWheelPreferences: SwiftFortuneWheelConfiguration.WheelPreferences {
let imageAnchor = SwiftFortuneWheelConfiguration.AnchorImage(imageName: "filled-circle",
let centerImageAnchor = SwiftFortuneWheelConfiguration.AnchorImage(imageName: "filled-circle",
size: CGSize(width: 10, height: 10),
verticalOffset: -circleStrokeWidth / 2,
tintColor: .white)
let preferences = SwiftFortuneWheelConfiguration.WheelPreferences(circlePreferences: .exampleCirclePreferences,
slicePreferences: .exampleRainbowSlicePreferenes,
imageAnchor: imageAnchor)
centerImageAnchor: centerImageAnchor)
return preferences
}
}
Expand Down Expand Up @@ -162,3 +162,12 @@ extension TextPreferences {
return prefenreces
}
}


extension LinePreferences {
static var defaultPreferences: LinePreferences {
let colorType = SwiftFortuneWheelConfiguration.ColorType.customPatternColors(colors: [.orange, .purple, .yellow, .blue, .brown, .green, .systemPink, .systemTeal, .brown, .green, .white, .black, .magenta], defaultColor: .red)
let preferences = LinePreferences(colorType: colorType, height: 2, verticalOffset: 0)
return preferences
}
}
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,9 @@ Please make sure to update tests as appropriate.

Sherzod Khashimov

## Changelog

See [**changelog here**](/Documentation/Changelog.md)

## License
[MIT](https://choosealicense.com/licenses/mit/)
Loading

0 comments on commit 8f70611

Please sign in to comment.