Skip to content

Instantly share code, notes, and snippets.

@jacklynrose
Created October 27, 2013 10:35
Show Gist options
  • Save jacklynrose/7180211 to your computer and use it in GitHub Desktop.
Save jacklynrose/7180211 to your computer and use it in GitHub Desktop.
This is how I managed to hack the visual format language to center a few views vertically (most other ways put them at the top and bottom, or just the top, or just the bottom). Basically what I'm doing is saying that the top margin should be less than or equal to half the portrait height minus the total height of all the views you'll be centring…
totalCombinedViewHeight = 100
Motion::Layout.new do |layout|
layout.view view
layout.subviews "state" => @state, "action" => @action
layout.metrics "margin" => 20, "height" => 40, "halfHeight" => ((view.bounds.size.height - totalCombinedViewHeight) / 2), "halfWidth" => ((view.bounds.size.width - 100) / 2)
layout.vertical "|-(<=halfHeight)-[state]-margin-[action]-(>=halfWidth)-|"
layout.horizontal "|-margin-[state]-margin-|"
layout.horizontal "|-margin-[action]-margin-|"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment