Skip to content

Instantly share code, notes, and snippets.

@dastels
Created October 2, 2013 18:10
Show Gist options
  • Select an option

  • Save dastels/6798015 to your computer and use it in GitHub Desktop.

Select an option

Save dastels/6798015 to your computer and use it in GitHub Desktop.
(let ((w (.window *app*))
(root (.init (UIView.)))
(input (.init (UITextField.)))
(output (.init (UITextField.)))
(convert-f-c (UIButton/buttonWithType: UIButtonTypeSystem))
(convert-c-f (UIButton/buttonWithType: UIButtonTypeSystem))
(close (UIButton/buttonWithType: UIButtonTypeSystem)))
(.frame= root '((10 200) (220 200)))
(.backgroundColor= root (UIColor/lightGrayColor))
(.frame= input '((10 10) (200 44)))
(.placeholder= input "Degrees F or C")
(.frame= output '((10 100) (200 44)))
(.frame= convert-f-c '((10 60) (100 44)))
(.backgroundColor= convert-f-c (UIColor/lightGrayColor))
(.setTitle:forState: convert-f-c "F -> C" UIControlStateNormal)
(.setTitleColor:forState: convert-f-c (UIColor/blackColor) UIControlStateNormal)
(.when convert-f-c UIControlEventTouchUpInside
(lambda ()
(let ((f (float (.text input)))
(c (* (/ 5.0 9.0) (- f 32))))
(.text= output (str c)))))
(.frame= convert-c-f '((110 60) (100 44)))
(.backgroundColor= convert-c-f (UIColor/lightGrayColor))
(.setTitle:forState: convert-c-f "C -> F" UIControlStateNormal)
(.setTitleColor:forState: convert-c-f (UIColor/blackColor) UIControlStateNormal)
(.when convert-c-f UIControlEventTouchUpInside
(lambda ()
(let ((c (float (.text input)))
(f (+ (* (/ 9.0 5.0) c) 32)))
(.text= output (str f)))))
(.frame= close '((10 150) (200 44)))
(.setTitle:forState: close "Close" UIControlStateNormal)
(.when close UIControlEventTouchUpInside
(lambda ()
(.removeFromSuperview root)))
(.addSubview root input)
(.addSubview root convert-f-c)
(.addSubview root convert-c-f)
(.addSubview root output)
(.addSubview root close)
(.addSubview w root))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment