Coder Social home page Coder Social logo

swift-layoutstuff-lab's Introduction

Frames & Bounds Lab

“Wonder. Go on and wonder.” ― William Faulkner, The Sound and the Fury

Overview

In this lab, you'll create an app where you'll work with frames and bounds in iOS.

Instructions

In this lab, you'll investigate how frames and bounds work in iOS, and experiment with them. When you're done, your app will look like this:

Frames & Bounds UI

You can adjust the sliders to dynamically change the frames and bounds of the kitty picture at the top of the app. Using this app, you'll be able to investigate the relationship between frames and bounds, and how changing their values will change how various elements of the app are drawn.

The app has two key elements: The photo of a kitten, and a yellow square that is initially in the top left corner of the kitten's image view.

Changing the "frame" sliders will move the location of the kitten image:

Changing Frames

On the other hand, changing the "bounds" sliders adjust the drawable rectangle of the kitten image, which has the effect of moving the yellow square:

Changing Bounds

Note that this lab does not use Auto Layout (it becomes more complicated to dynamically change the frame and bounds of a view when Auto Layout is enabled), so for best results, you should run this app in the iPhone 5S simulator.

Some parts of this app have been provided to you. Here's what you need to do to finish the app and have your own working version:

  1. Open up Main.storyboard, then open up ViewController.swift in an assistant editor.
  2. Control-drag an IB outlet called imageView from the kitten's UIImageView to ViewController.
  3. Control-drag IB outlets for each slider to ViewController. Name them frameXSlider, frameYSlider, boundsXSlider, and boundsYSlider.
  4. Control-drag IB outlets for each text label to ViewController. Name them frameXLabel, frameYLabel, boundsXLabel, and boundsYLabel.
  5. Four IB actions have already been created in ViewController: frameXChanged, frameYChanged, boundsXChanged, and boundsYChanged. Control-drag a connection from each slider to the appropriate IB action method in order to hook the sliders up to the ViewController.

Once you've completed this lab, build and run your app in an iPhone 5S simulator. Play around with the sliders a bit to see how it changes how the kitty's image view and yellow square change in response to change changes in the kitty view's frame and bounds.

Extra Credit

  • Add four new sliders for imageView's frame's width and height, and imageView's bound's width and height, and IB actions that will adjust the value of those properties.

View this lesson on Learn.co

swift-layoutstuff-lab's People

Contributors

annjohn avatar jimcampagno avatar johann avatar mdippery avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swift-layoutstuff-lab's Issues

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.