Animals Tutorial Lesson 6

Adding Custom Captions

Watch the video: https://youtu.be/zi77-chrkRc
  1. Change the Animal struct to add a caption property
struct Animal {
    var caption   : String
    var imageFile : String
    var color     : UIColor
}
  1. Add captions to each of the data elements. These are the captions I used. Please change the captions to something you like better.
    init () {
        data = [
            "Cheetah"    : Animal (
                caption   : "Cheetah (fast guy)",
                imageFile : "cheetah",
                color     : UIColor.brownColor()),
            "Cow"        : Animal (
                caption   : "Cow (please do not tip)",
                imageFile : "cow",
                color     : UIColor.yellowColor()),
            "Duck"       : Animal (
                caption: "Duck (quack)",
                imageFile: "duck",
                color: UIColor.cyanColor()),
            "Elephant"   : Animal (
                caption: "Elephant (big guy)",
                imageFile: "elephant",
                color: UIColor.brownColor()),
            "Lion"       : Animal (
                caption: "Lion (king)",
                imageFile: "lion",
                color: UIColor.brownColor()),
            "Salamander" : Animal (
                caption: "Salamander (slippery)",
                imageFile: "salamander",
                color: UIColor.init(red: 0.7, green: 0.3, blue: 0.5, alpha: 1)),
            "Tarsier"    : Animal (
                caption: "Tarsier (who?)",
                imageFile: "tarsier",
                color: UIColor.init(red: 0.4, green: 0.7, blue: 0.4, alpha: 1))
        ]
    }
  1. Change this line in the ButtonController.swift file in the prepareForSegue method:
destination.mytitle = data.getAnimal(animal!).caption
  1. Move the caption down a little so it does not bump against the toolbar.
  2. After moving the caption, select the triangle tool and update the constraints.
  3. Add a background color to the back button.
  4. Change the color of the text in the back button so it is more visible against the background color.
  5. Make the back button larger so the text doesn't bump against the edges of the button.



No comments:

Post a Comment