可以创建选项卡 - 但是,如何将图形插入每个选项卡以及选择选项卡后如何将其调出到新屏幕?
# 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
最佳答案
请参阅 https://github.com/HipByte/RubyMotionSamples 中的“Beers”示例项目
您走在正确的轨道上,唯一的区别是您需要列出特定的 View Controller 类而不是通用的 UIViewController 类。来自示例:
tabbar.viewControllers = [BeerMapController.alloc.init,
BeerListController.alloc.init]
然后在每个 Controller 的 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
或者,如果您还没有特定的 View Controller ,我想您可以这样做:
tabbar.viewControllers = [
UIViewController.alloc.init,
UIViewController.alloc.init
]
tabbar.viewControllers[0].tabBarItem = UITabBarItem.alloc.initWithTitle('List', image:UIImage.imageNamed('list.png'), tag:1)
# etc.
关于ios - 如何将图像插入到 UIViewController 创建的栏中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11036248/