Created
November 17, 2012 22:35
-
-
Save sherbondy/4100842 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class ColorsController < UIViewController | |
def viewDidLoad | |
super | |
self.view.backgroundColor = UIColor.whiteColor | |
@label = UILabel.alloc.initWithFrame(CGRectZero) | |
@label.text = "Colors" | |
@label.sizeToFit | |
@label.center = [ | |
self.view.frame.size.width / 2, | |
(self.view.frame.size.height - 80) / 2] | |
@label.autoresizingMask = | |
UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin | |
self.view.addSubview @label | |
self.title = "Colors" | |
@colors = ["red", "green", "blue"] | |
@colors.each_with_index do |color_text, index| | |
color = color_named(color_text) | |
button_width = 80 | |
button = UIButton.buttonWithType(UIButtonTypeRoundedRect) | |
button.tag = index | |
button.setTitle(color_text, forState:UIControlStateNormal) | |
button.setTitleColor(color, forState:UIControlStateNormal) | |
button.sizeToFit | |
button.frame = [[30 + index*(button_width + 10), | |
self.view.frame.size.height / 2], | |
[80, button.frame.size.height]] | |
button.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin | |
button.addTarget(self, action: "tap_color:", forControlEvents:UIControlEventTouchUpInside) | |
self.view.addSubview button | |
end | |
end | |
def color_named(color_text) | |
UIColor.send("#{color_text}Color") | |
end | |
def tap_color(sender) | |
color = color_named(@colors[sender.tag]) | |
controller = ColorDetailController.alloc.initWithColor(color) | |
self.navigationController.pushViewController(controller, animated: true) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment