Last active
August 29, 2015 14:18
-
-
Save Aaron-A-zz/fc83296741cb79f1eac9 to your computer and use it in GitHub Desktop.
Lesson 2 Visuals and UIView @Thinkful
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Playground - noun: a place where people can play | |
import UIKit | |
import XCPlayground | |
class Shape: UIView { | |
var color: UIColor | |
init(color: UIColor) { | |
self.color = color | |
super.init(frame: CGRectZero) | |
self.backgroundColor = color | |
} | |
required init(coder aDecoder: NSCoder) { | |
fatalError("init(coder:) has not been implemented") | |
} | |
func getArea() -> Double { | |
return 0 | |
} | |
} | |
// Square | |
class Square: Shape { | |
var width:Int | |
init(width:Int, color: UIColor) { | |
self.width = width | |
super.init(color: color) | |
self.frame.size = CGSize(width: width, height: width) | |
} | |
required init(coder aDecoder: NSCoder) { | |
fatalError("init(coder:) has not been implemented") | |
} | |
override func getArea() -> Double { | |
return(Double(width * width)) | |
} | |
} | |
//Circle | |
class Circle: Shape { | |
var radius: Int | |
init(radius:Int, color: UIColor){ | |
self.radius = radius | |
super.init(color: color) | |
self.frame.size = CGSize(width: radius * 2, height: radius * 2) | |
self.layer.cornerRadius = CGFloat(radius) | |
} | |
required init(coder aDecoder: NSCoder) { | |
fatalError("init(coder:) has not been implemented") | |
} | |
override func getArea() -> Double { | |
return(M_PI * Double(radius * radius)) | |
} | |
} | |
var square = Square(width: 100, color: UIColor.redColor()) | |
square.center = CGPoint(x: 200, y: 200) | |
square.getArea() | |
var circle = Circle(radius: 50, color: UIColor.blueColor()) | |
circle.center = CGPoint(x: 100, y: 100) | |
circle.getArea() | |
let view = UIView(frame: CGRect(x: 0, y: 0, width: 320, height: 320)) | |
XCPShowView("Shapes!", view) | |
view.addSubview(circle) | |
view.addSubview(square) | |
class Rectangle: Shape { | |
var height: Int | |
var width: Int | |
var radius: Int | |
init(height: Int, width: Int, radius: Int, color: UIColor){ | |
self.height = height | |
self.width = width | |
self.radius = radius | |
super.init(color: color) | |
self.frame.size = CGSize(width: width, height: height) | |
self.layer.cornerRadius = CGFloat(radius) | |
} | |
required init(coder aDecoder: NSCoder) { | |
fatalError("init(coder:) has not been implemented") | |
} | |
override func getArea() -> Double { | |
return(Double(width * height)) | |
} | |
} | |
//Comprehension Check | |
var RoundedRectangle = Rectangle(height: 50, width: 200, radius: 3, color: UIColor.greenColor()) | |
RoundedRectangle.center = CGPoint(x: 300, y: 300) | |
view.addSubview(RoundedRectangle) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment