Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @IBOutlet weak var radioButBoth: UIButton! {
- didSet {
- radioButBoth.setImage(UIImage(named:"unchecked"), for: .normal)
- radioButBoth.setImage(UIImage(named:"checked"), for: .selected)
- }
- }
- @IBAction func radioButMethod(_ sender: UIButton) {
- radioButBoth.isSelected = false
- radioButOnline.isSelected = false
- radioButOffline.isSelected = false
- if sender == radioButOnline {
- debugPrint("radioButOnline")
- radioButOnline.checkboxAnimation {
- }
- } else if sender == radioButOffline {
- debugPrint("radioButOffline")
- radioButOffline.checkboxAnimation {
- }
- } else if sender == radioButBoth {
- debugPrint("radioButBoth")
- radioButBoth.checkboxAnimation {
- }
- }
- }
- extension UIButton {
- //MARK:- Animate check mark
- func checkboxAnimation(closure: @escaping () -> Void){
- guard let image = self.imageView else {return}
- UIView.animate(withDuration: 0.1, delay: 0.1, options: .curveLinear, animations: {
- image.transform = CGAffineTransform(scaleX: 0.85, y: 0.85)
- }) { (success) in
- UIView.animate(withDuration: 0.1, delay: 0, options: .curveLinear, animations: {
- self.isSelected = !self.isSelected
- //to-do
- closure()
- image.transform = .identity
- }, completion: nil)
- }
- }
- }
- @discardableResult
- private func checked(index: Int? = nil) -> Int {
- if index != nil {
- if index == 1 {
- radioButOnline.isSelected = true
- } else if index == 2 {
- radioButOffline.isSelected = true
- } else {
- radioButBoth.isSelected = true
- }
- } else {
- if radioButOnline.isSelected {
- return 1
- } else if radioButOffline.isSelected {
- return 2
- } else if radioButBoth.isSelected {
- return 3
- }
- }
- return 0
- }
- let tuitionType:Int = checked()
- self.checked(index: self.tutorDetail.tuition_type)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement