Skip to content

Instantly share code, notes, and snippets.

@kennylugo
Last active January 11, 2016 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kennylugo/41e2b76e03c1b8e8f842 to your computer and use it in GitHub Desktop.
Save kennylugo/41e2b76e03c1b8e8f842 to your computer and use it in GitHub Desktop.
NYCDA's Triplet Interfaces Programatically
//
// ViewControllerC.swift
// TripletInterfaces
//
// Created by Kenny Batista on 6/16/15.
// Copyright (c) 2015 Kenny Batista. All rights reserved.
//
import UIKit
class ViewControllerC: UIViewController {
//TODO: Replicate the appearance and behavior of ViewControllerA, but do so programmatically
//The only difference should be that the right most button will trigger a segue to the "FinViewController"
var imageView:UIImageView?
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.darkGrayColor()
let gameBoyView = UIView(frame: CGRect(x: 16, y: 72, width: 300, height: 400))
gameBoyView.backgroundColor = UIColor.lightGrayColor()
self.view.addSubview(gameBoyView)
imageView = UIImageView(frame: CGRect(x: 8, y:8, width: 284, height : 213))
if let imageView_ = imageView {
let theImage = UIImage(named: "mario")
imageView_.image = theImage
gameBoyView.addSubview(imageView!)
}
let rightButton = UIButton(frame: CGRect(x: 230, y: 274, width: 40, height: 40))
rightButton.backgroundColor = UIColor.redColor()
let leftButton = UIButton(frame: CGRect(x:182, y: 298, width: 40, height:40))
leftButton.backgroundColor = UIColor.redColor()
gameBoyView.addSubview(leftButton)
gameBoyView.addSubview(rightButton)
leftButton.addTarget(self, action: "leftButtonHit",
forControlEvents: .TouchUpInside)
rightButton.addTarget(self, action: "rightButtonHit",
forControlEvents: .TouchUpInside)
let right2Button = UIButton(frame: CGRect(x: 37, y: 298, width: 90, height: 23))
right2Button.backgroundColor = UIColor.blackColor()
let left2Button = UIButton(frame: CGRect(x:70, y: 265, width: 25, height:90))
left2Button.backgroundColor = UIColor.blackColor()
gameBoyView.addSubview(left2Button)
gameBoyView.addSubview(right2Button)
}
func leftButtonHit() {
if let imageView_ = imageView {
let newImage = UIImage(named: "gameOver")
imageView_.image = newImage
}
}
func rightButtonHit(){
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("FIN")
self.navigationController?.pushViewController(vc, animated: true)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment