Skip to content

Instantly share code, notes, and snippets.

@dvdsgl
Created June 10, 2014 16:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvdsgl/e596941de042348b53b7 to your computer and use it in GitHub Desktop.
Save dvdsgl/e596941de042348b53b7 to your computer and use it in GitHub Desktop.
Cirrious.FluentLayout makes iOS Auto Layout... fun! Especially in F#.
open System
open MonoTouch.UIKit
open Cirrious.FluentLayouts.Touch
type PhotoViewController() =
inherit UIViewController()
let imageViewSize = 200.0f
let imageView =
let view = UIImageView(
BackgroundColor = UIColor.Gray,
ContentMode = UIViewContentMode.ScaleAspectFit,
TranslatesAutoresizingMaskIntoConstraints = false)
view
let photoButton =
let button = UIButton(
UIButtonType.System,
TranslatesAutoresizingMaskIntoConstraints = false)
button.SetTitle("Add photo", UIControlState.Normal)
button
let content =
let view = UIView(BackgroundColor = UIColor.White)
view.AddSubviews(imageView, photoButton)
view.AddConstraints [|
imageView.Width().EqualTo(imageViewSize)
imageView.Height().EqualTo(imageViewSize)
imageView.WithSameCenterX(view)
imageView.AtTopOf(view, 50.0f)
photoButton.WithSameCenterX(view)
photoButton.Below(imageView, 20.0f)
|]
view
override this.LoadView() = this.View <- content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment