Created
July 23, 2012 13:16
-
-
Save satococoa/3163564 to your computer and use it in GitHub Desktop.
UIAlertView, UIActionSheet
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 MyViewController < UIViewController | |
| def viewDidLoad | |
| super | |
| view.backgroundColor = UIColor.whiteColor | |
| button = UIButton.buttonWithType(UIButtonTypeRoundedRect).tap do |b| | |
| b.frame = [[30.0, 30.0], [200.0, 30.0]] | |
| b.setTitle("Click", forState:UIControlStateNormal) | |
| b.addTarget(self, action: 'open_action_sheet:', forControlEvents: UIControlEventTouchUpInside) | |
| end | |
| view.addSubview(button) | |
| alert_button = UIButton.buttonWithType(UIButtonTypeRoundedRect).tap do |b| | |
| b.frame = [[30.0, 80.0], [200.0, 30.0]] | |
| b.setTitle("Click", forState:UIControlStateNormal) | |
| b.addTarget(self, action: 'open_alert:', forControlEvents: UIControlEventTouchUpInside) | |
| end | |
| view.addSubview(alert_button) | |
| end | |
| def open_alert(sender) | |
| alert = UIAlertView.alloc.initWithTitle('ALERT', message:'hogehoge', delegate:self, cancelButtonTitle:'Cancel', otherButtonTitles:nil) | |
| alert.show | |
| end | |
| def open_action_sheet(sender) | |
| as = UIActionSheet.alloc.initWithTitle("SELECT", delegate: self, cancelButtonTitle: "CANCEL", destructiveButtonTitle: "OK", otherButtonTitles: nil) | |
| as.showInView(view) | |
| end | |
| def actionSheet(actionSheet, clickedButtonAtIndex: buttonIndex) | |
| puts "press #{buttonIndex}" | |
| end | |
| end | |
| class AppDelegate | |
| def application(application, didFinishLaunchingWithOptions:launchOptions) | |
| @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds) | |
| my_controller = MyViewController.new | |
| @window.rootViewController = my_controller | |
| @window.makeKeyAndVisible | |
| true | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment