Giter Site home page Giter Site logo

swift-layoutfun-lab-dumbo-web-082718's Introduction

Stack the Squares

The best thing for being sad," replied Merlin, beginning to puff and blow, "is to learn something. That's the only thing that never fails. You may grow old and trembling in your anatomies, you may lie awake at night listening to the disorder of your veins, you may miss your only love, you may see the world about you devastated by evil lunatics, or know your honour trampled in the sewers of baser minds. There is only one thing for it then โ€” to learn. Learn why the world wags and what wags it. That is the only thing which the mind can never exhaust, never alienate, never be tortured by, never fear or distrust, and never dream of regretting. Learning is the only thing for you. Look what a lot of things there are to learn. -T.H. White

Learning Objectives

  • Create constraints in code with multiple UIView objects

Instructions

Here is the finished product:

You will be building this.. in code. We will not be using Interface Builder to lay out our views here.

Locating the ViewController.swift file you will find that there are some instance properties and methods provided to you.

First, lets look at the instance properties provided.

  let redView = UIView(frame: CGRect.zero)
  let orangeView = UIView(frame: CGRect.zero)
  let yellowView = UIView(frame: CGRect.zero)
  let greenView = UIView(frame: CGRect.zero)
  let blueView = UIView(frame: CGRect.zero)

There are five UIView objects here. Each one has no frame, not only that.. each one isn't added to another UIView instance which means they aren't displayed anywhere.

The viewDidLoad() method has some method calls in it:

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = UIColor.gray
        turnOffAutoResizingOnAllViews()
        setupTheConstraints()
        setupColors()
    }

First, we're setting the backgroundColor of the view instance to be gray. Then we're calling on the turnOffAutoResizingOnAllViews() method which (if you take a look at the implementation) is setting the translatesAutoresizingMaskIntoConstraints property on our instance properties to false. This will allow us to provide constraints in code (not using Interface builder). As well, we're adding all of these view objects to the view instance (which will allow these 5 view objects to be visible on screen). But.. they won't be visible on screen just yet, it's on you to create the constraints!

Take a look at the setupTheConstraints() function, you should find a TODO: Comment. It's your job to create all the necessary constraints (in code) for all of these views so that when you run your app, it looks like the screenshot above.

Some hints. Each view must be a perfect square, meaning.. its height equals its width.

The redView's width should be equal to half the width of the iPhone (or view). The bottom of the redView should sit flush on the bottom of the view.

Each view (excluding the redView) object should be 75% of the width of the view below it and it should sit flush on top of it.

View this lesson on Learn.co

swift-layoutfun-lab-dumbo-web-082718's People

Contributors

jimcampagno avatar johann avatar

Watchers

Kevin McAlear avatar  avatar Victoria Thevenot avatar Belinda Black avatar  avatar Joe Cardarelli avatar Sam Birk avatar Sara Tibbetts avatar The Learn Team avatar Sophie DeBenedetto avatar  avatar Jaichitra (JC) Balakrishnan avatar Antoin avatar Alex Griffith avatar  avatar Amanda D'Avria avatar  avatar Nicole Kroese  avatar  avatar Lore Dirick avatar Nicolas Marcora avatar Lisa Jiang avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.