iOS Swift application for easy bill splitting at the restaurant

iOS Swift application for easy bill splitting at the restaurant
02/04/2019 Ernestas Konopliovas
In Back-end, Swift
Short description

This app is just a small but very handy tool for bill splitting in the restaurant. Input bill total, by how many persons to divide, how much you want to leave for tip and you will immediately see how much everyone need to pay.

How it looks like
Demonstration
Code, I used
  1. import UIKit
  2. class ViewController: UIViewController {
  3. @IBOutlet weak var stepperDevide: UIStepper!
  4. @IBOutlet weak var txtBillTotalField: UITextField!
  5. @IBOutlet weak var txtEach: UILabel!
  6. @IBOutlet weak var txtDevideCount: UILabel!
  7. var total:Float = 0.0
  8. @IBOutlet weak var txtTip: UILabel!
  9. @IBOutlet weak var txtPercentForTip: UILabel!
  10. @IBOutlet weak var sliderTip: UISlider!
  11. override func viewDidLoad() {
  12. super.viewDidLoad()
  13. let tapGesture = UITapGestureRecognizer(target: self,action:#selector(hideKeyboard))
  14. txtBillTotalField.keyboardType = UIKeyboardType.numbersAndPunctuation
  15. view.addGestureRecognizer(tapGesture)
  16. }
  17. @objc func hideKeyboard() {
  18. view.endEditing(true)
  19. }
  20. @IBAction func sliderListener(_ sender: Any) {
  21. refreshLabels()
  22. }
  23. @IBAction func txtBillTotal(_ sender: Any) {
  24. refreshLabels()
  25. }
  26. @IBAction func stepperListener(_ sender: Any) {
  27. refreshLabels()
  28. }
  29. func refreshLabels(){
  30. total = (txtBillTotalField.text!.replacingOccurrences(of: “,”, with: “.”) as NSString).floatValue
  31. let tipTax = total * sliderTip.value.rounded() * 0.01
  32. let devide = Float(stepperDevide.value)
  33. let each = (total + tipTax) / devide
  34. txtEach.text = (NSString(format: “%.2f€”, each) as String).replacingOccurrences(of: “.”, with: “,”)
  35. txtDevideCount.text = NSString(format: “%.0f”, devide) as String
  36. txtTip.text = (NSString(format: “%.2f€”, tipTax) as String).replacingOccurrences(of: “.”, with: “,”)
  37. txtPercentForTip.text = NSString(format: “%.0f”, sliderTip.value) as String + “% for tip”
  38. }
  39. }


		

Comments (0)

Leave a reply

Your email address will not be published. Required fields are marked *

*