如何将图像插入由UIViewController创建的栏中?

时间:2012-06-14 15:18:43

标签: ios rubymotion

可以创建标签 - 但是,如何在每个标签中插入图形,当选择标签时,如何将其调出到新屏幕?

# Create a tabbar
tabbar = UITabBarController.alloc.init

# Each Tab has a view controller allocated

tabbar.viewControllers = [
    UIViewController.alloc.init,
    UIViewController.alloc.init, 
    UIViewController.alloc.init,
    UIViewController.alloc.init
]

# Selected index to 0
tabbar.selectedIndex = 0

# The root view controller also changed
@window.rootViewController = UINavigationController.alloc.initWithRootViewController(tabbar)

# We will force to use a full screen layout.
@window.rootViewController.wantsFullScreenLayout = true

1 个答案:

答案 0 :(得分:2)

请参阅https://github.com/HipByte/RubyMotionSamples

上的“啤酒”示例项目

您走在正确的轨道上,唯一的区别是您需要列出特定的视图控制器类而不是通用的UIViewController类。来自样本:

tabbar.viewControllers = [BeerMapController.alloc.init,
                          BeerListController.alloc.init]

然后在每个控制器的init方法中,设置tabBarItem为其提供标题和图片:

class BeerListController < UITableViewController
  def init
    if super
      self.tabBarItem = UITabBarItem.alloc.initWithTitle('List', image:UIImage.imageNamed('list.png'), tag:1)
    end
    self
  end
end

或者,如果您还没有特定的视图控制器,我想您可以这样做:

tabbar.viewControllers = [
  UIViewController.alloc.init,
  UIViewController.alloc.init
]
tabbar.viewControllers[0].tabBarItem = UITabBarItem.alloc.initWithTitle('List', image:UIImage.imageNamed('list.png'), tag:1)
# etc.