Weitere ähnliche Inhalte Ähnlich wie iOS Development with RubyMotion (20) Kürzlich hochgeladen (20) iOS Development with RubyMotion7. No More Objective-C?
ObjectiveC
NSString *list = [NSString alloc] initWithString: @"Karin, Carrie, David"];
NSArray *listItems = [list componentsSeparatedByString:@", "];
[list stringByReplacingOccurrencesOfString:@", " withString:@" - "]
Ruby
list = 'Karin, Carrie, David'
list_items = list.split(', ')
list.gsub!(/, /, ' - ')
19. AppDelegate.m
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
CGRect frame = CGRectMake(20, 50, 280, 50);
UILabel *label = [[UILabel alloc] init];
label.text = @"Hello World";
label.textColor = [UIColor whiteColor];
label.frame = frame;
[self.window makeKeyAndVisible];
[self.window addSubView label];
return YES;
}
20. Creating an Application
$ motion create hello_world
Create hello_world
Create hello_world/.gitignore
Create hello_world/app/app_delegate.rb
Create hello_world/Gemfile
Create hello_world/Rakefile
Create hello_world/resources/Default-568h@2x.png
Create hello_world/resources/Default-667h@2x.png
Create hello_world/resources/Default-736h@3x.png
Create hello_world/spec/main_spec.rb
21. app_delegate.rb
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
label = UILabel.new
label.text = "Hello World"
label.textColor = UIColor.whiteColor
label.frame = [[20, 50], [280, 50]]
@window.addSubview(label)
@window.makeKeyAndVisible
true
end
end
24. class CameraController < UIViewController
def viewDidLoad
view.backgroundColor = UIColor.underPageBackgroundColor
@picker = UIImagePickerController.alloc.init
@picker.delegate = self
@picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum
@picker.setMediaTypes([KUTTypeImage])
load_buttons
end
def load_buttons
btn = UIButton.buttonWithType(UIButtonTypeRoundedRect)
btn.frame = [[50, 20], [200, 50]]
btn.setTitle('Select an image', forState:UIControlStateNormal)
btn.addTarget(self, action: :select_image, forControlEvents:UIControlEventTouchUpInside
view.addSubview(btn)
end
def select_image
self.presentModalViewController(@picker, animated: true)
end
def imagePickerController(picker, didFinishPickingMediaWithInfo: info)
dismissModalViewControllerAnimated(true)
image_view = UIImageView.alloc.initWithImage(info.valueForKey("UIImagePickerControllerOr
image_view.frame = [[50, 200], [200, 180]]
view.addSubview(image_view)
end
end
25. Bubblewrap and RMQ
class CameraController < UIViewController
def viewDidLoad
view.backgroundColor = UIColor.underPageBackgroundColor
load_buttons
end
def load_buttons
btn = UIButton.buttonWithType(UIButtonTypeRoundedRect)
btn.setTitle('Select an image', forState: UIControlStateNormal)
btn = rmq.append(btn).layout(l: 50, t: 20, w: 200, h: 50)
btn.on(:tap) { select_image }
end
def select_image
BW::Device.camera.any.picture(media_types: [:image]) do |result|
image_view = UIImageView.alloc.initWithImage(result[:original_image])
rmq.append(image_view).layout(l: 50, t: 200, w: 200, h: 180)
end
end
end