I am writing a Rubymotion app and I want to customize the TabBar. On NSScreencasts.com they explain how to do it in Objective-C but how can I transform the below code into Ruby?
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self customize];
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
[self customize];
}
return self;
}
- (void)customize {
UIImage *tabbarBg = [UIImage imageNamed:@"tabbar-background.png"];
UIImage *tabBarSelected = [UIImage imageNamed:@"tabbar-background-pressed.png"];
[self setBackgroundImage:tabbarBg];
[self setSelectionIndicatorImage:tabBarSelected];
}
@end
This is my attempt:
class CustomTabbar < UITabBarController
def init
super
customize
self
end
def customize
tabbarBg = UIImage.imageNamed('tabbar.jpeg')
self.setBackgroundImage = tabbarBg
end
end
But if I run it I get this error:
Terminating app due to uncaught exception 'NoMethodError', reason: 'custom_tabbar.rb:5:in `init': undefined method `setBackgroundImage=' for #<CustomTabbar:0x8e31a70> (NoMethodError)
UPDATE
*This is my app_delete file:*
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
first_controller = FirstController.alloc.init
second_controller = SecondController.alloc.init
tabbar_controller = CustomTabbar.alloc.init
tabbar_controller.viewControllers = [first_controller, second_controller]
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
@window.rootViewController = tabbar_controller
@window.makeKeyAndVisible
true
end
end