ios - 如何将图像插入到 UIViewController 创建的栏中?

标签 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

最佳答案

请参阅 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/

相关文章:

ruby - 初始化 ruby​​ 单例

iphone - 用于跨选项卡保留 UI 状态的单例

ios - NSURLSession 具有后台配置和应用程序被用户杀死

ios - 当两个 TableView 单元格具有大部分相同的组件时,只设置一次值

ios - 如何将 React Native 与 RubyMotion 结合使用

ruby - 新的 RubyMotion 和 Joybox 的问题

iphone - 当我将它们翻译成另一种语言时,正则表达式是否有效?

ios - 如何为 iPhone 6 和 iPhone 6-Plus 优化非常老式的 iOS 应用程序

ios - (Rubymotion) 如何在 Formotion 中执行此自定义 View ?

ios - 在 UITableView 页脚中动态设置和调整标签大小