tapptitude / TTFortuneWheel-iOS

Fortune spinning wheel that supports custom drawing.
MIT License
132 stars 41 forks source link

Replace slice name with text field text #29

Closed umutalparslan closed 5 years ago

umutalparslan commented 5 years ago

Hello,

I want to replace slice name with textfield text. How can i do this?

` import UIKit import TTFortuneWheel import SwiftMessages

class spinWheel: UIViewController {

@IBOutlet weak var spinningWheel: TTFortuneWheel!
@IBOutlet weak var wheelFrame: UIImageView!
@IBOutlet weak var rotateButton: UIButton!
@IBOutlet weak var text1: UITextField!
@IBOutlet weak var text2: UITextField!
@IBOutlet weak var text3: UITextField!
@IBOutlet weak var text4: UITextField!
@IBOutlet weak var text5: UITextField!
@IBOutlet weak var text6: UITextField!

override func viewDidLoad() {
    super.viewDidLoad()
    spinningWheel.isHidden = true
    wheelFrame.isHidden = true
    rotateButton.isHidden = true

    let slices = [ CarnivalWheelSlice.init(title: "\(text1.text!)"),
                   CarnivalWheelSlice.init(title: "\(text2.text!)"),
                   CarnivalWheelSlice.init(title: "\(text3.text!)"),
                   CarnivalWheelSlice.init(title: "\(text4.text!)"),
                   CarnivalWheelSlice.init(title: "\(text5.text!)"),
                   CarnivalWheelSlice.init(title: "\(text6.text!)")]
    spinningWheel.slices = slices
    spinningWheel.equalSlices = true
    spinningWheel.frameStroke.width = 0
    spinningWheel.slices.enumerated().forEach { (pair) in
        let slice = pair.element as! CarnivalWheelSlice
        let offset = pair.offset
        switch offset % 4 {
        case 0: slice.style = .brickRed
        case 1: slice.style = .sandYellow
        case 2: slice.style = .babyBlue
        case 3: slice.style = .deepBlue
        default: slice.style = .brickRed
        }
    }

}
@IBAction func rotateButton(_ sender: Any) {
    spinningWheel.startAnimating()
    DispatchQueue.main.asyncAfter(deadline: .now() + 4.0) {
        self.spinningWheel.startAnimating(fininshIndex: 5) { (finished) in
            print(finished)
        }
    }
}

@IBAction func onayButton(_ sender: Any) {

        if (text1.text != "" && text2.text != "" && text3.text != "" && text4.text != "" && text5.text != "" && text6.text != "") {
            spinningWheel.isHidden = false
            wheelFrame.isHidden = false
            rotateButton.isHidden = false

        } else {
            let messageView: MessageView = MessageView.viewFromNib(layout: .messageView)
            messageView.configureBackgroundView(width: 250)
            messageView.configureContent(title: "hata", body: "lütfen önce yemek isimleri girin", iconImage: nil, iconText: "❓", buttonImage: nil, buttonTitle: "kapat") { _ in
                SwiftMessages.hide()
            }
            messageView.backgroundView.backgroundColor = UIColor.init(white: 0.97, alpha: 1)
            messageView.backgroundView.layer.cornerRadius = 10
            var config = SwiftMessages.defaultConfig
            config.presentationStyle = .bottom
            config.duration = .forever
            config.dimMode = .blur(style: .dark, alpha: 0.85, interactive: true)
            config.presentationContext  = .window(windowLevel: UIWindow.Level.statusBar)
            SwiftMessages.show(config: config, view: messageView)
    }

}

} ` spin.mov.zip

EfraimB commented 5 years ago

Hello, unfortunately there is no straightforward way to have titles to be textfields, as the wheel is single uiview with multiple layers. Though what you can do is to intercept touches on specific slice layer and overlay a textfield at the title's current position and rotation.

umutalparslan commented 5 years ago

Hello @EfraimB ,

Thank you for quick answer. I'll try. I just have one more question. The yellow mark on the wheel always stays in the same place. The yellow mark in the video. How can I solve this?

EfraimB commented 5 years ago

Well, the frame of the wheel is not part of the TTFortuneWheel view. That's just an overlay image, you can replace it with which-ever asset you like.