Skip to content

Instantly share code, notes, and snippets.

@austinzheng
Created June 3, 2014 04:17
Show Gist options
  • Save austinzheng/d68d84b6c57dc61aa297 to your computer and use it in GitHub Desktop.
Save austinzheng/d68d84b6c57dc61aa297 to your computer and use it in GitHub Desktop.
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
addSquareToView(size: CGSizeMake(30, 30), color: UIColor.greenColor());
}
func addSquareToView(size s: CGSize, color: UIColor) {
var square: UIView;
let frame = CGRectMake(10, 10, s.width, s.height);
// This is equivalent to [[UIView alloc] initWithFrame:frame]
square = UIView(frame: frame);
square.backgroundColor = color;
self.view.addSubview(square);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment