0

I'm very new to RubyMotion and iOS development and I wanna put a top bar in my app, like this one from groupme and place an icon in the middle of it.

How do I do that? What is the library? How do I attach it to the view?

There is the code in my app_delegate.rb, currently:

class AppDelegate
  def application(application, didFinishLaunchingWithOptions:launchOptions)
    @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)

    tabbar = UITabBarController.alloc.init
    tabbar.viewControllers = [
        ProductMapController.alloc.init,
        SearchController.alloc.init,
        NewProductController.alloc.init,
        FeedController.alloc.init,
        UserDetailsController.alloc.init
    ]
    tabbar.selectedIndex = 0
    @window.rootViewController = UINavigationController.alloc.initWithRootViewController(tabbar)
    @window.rootViewController.wantsFullScreenLayout = true
    @window.makeKeyAndVisible

    true
  end
end

Thank you, I appreciate any help you can give me.

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
rodrigoalvesvieira
  • 7,895
  • 15
  • 63
  • 84
  • 1
    There's no library, you build it yourself. The background image of the bar would be a UIImageView. Then create a UIButton and add it as a subview. Voila, done. :) – WendiKidd Jul 01 '12 at 22:09
  • This sounds easy when you say but I'm so newbie, how would you do that in the code above, can you tell me? – rodrigoalvesvieira Jul 02 '12 at 03:55
  • The code you've posted above is familiar to me in content but not syntax; I program iOS in Objective-C, not ruby. But I'm sure there is documentation out there for how to place images and buttons on the screen in ruby, yes? – WendiKidd Jul 02 '12 at 22:50

2 Answers2

2

I found the solution for this:

In my app_delegate.rb I have:

items_controller = ProductsController.alloc.initWithNibName(nil, bundle: nil)
@window.rootViewController = UINavigationController.alloc.initWithRootViewController(items_controller)

then in my items_controller.rb I have:

self.navigationItem.titleView = UIImageView.alloc.initWithImage(UIImage.imageNamed('logo.png'))

I think this is totally fine because i'm not really polluting my app_delegate.rb anymore :)

If you have a better solution, please tell me.

rodrigoalvesvieira
  • 7,895
  • 15
  • 63
  • 84
0

Here is an idea of what you want:

class AppDelegate
  def application(application, didFinishLaunchingWithOptions:launchOptions)
    @window = UIWindow.alloc.initWithFrame UIScreen.mainScreen.bounds
    @window.makeKeyAndVisible

    #creates a bar with a width of 320, a height of 100, and colors it blue
    bar = UIView.alloc.initWithFrame [[0, 0], [320, 100]]  
    bar.backgroundColor = UIColor.blueColor 

    #creates an imageView with the icon, change the coordinates to center your icon
    icon= UIImageView.alloc.initWithFrame([[100,0], [100,100]]) 
    icon.image = UIImage.imageNamed('youricon.jpeg')

    #adds the bar and icon to the window
    @window.addSubview bar
    @window.addSubview icon

    true
  end
end

You don't want this sort of code in your app delegate but I added it here to give you a simple example.

Josh
  • 5,631
  • 1
  • 28
  • 54