在目标C中,可以将背景图像设置为拉伸的png,如下所示:
button = [[UIButton alloc] initWithFrame:CGRectMake(10, 0, 300, 44)];
[button setTitle: @"Tap me" forState: UIControlStateNormal];
[button setBackgroundImage:[[UIImage imageNamed: @"greenButton.png"]
stretchableImageWithLeftCapWidth:8.0f
topCapHeight:0.0f]
forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)
试图将其转换为Ruby,我不断获得例外.问题是用两种方法呼吁UIImage的实例:stretchableImageWithLeftCapWidth和topCapHeight.
我试过以下无济于事:
greenImage = UIImage.imageNamed("greenButton.png")
greenImage.stretchableImageWithLeftCapWidth = 8.0
greenImage.topCapHeight = 0.0
@timerButton.setBackgroundImage(greenImage, forState: UIControlStateNormal)
Run Code Online (Sandbox Code Playgroud)
任何人都可以建议吗?
我对RubyMotion开发比较陌生,但我已经在Objective-C中有过iOS的经验.
当我开始使用RubyMotion时,我找到了相当多的库.网络,数据存储等都有一些有用的库,但最让我困惑的是这些布局(UI)库.
有一堆,最流行的是: - SweetTea - SugarCube(不是真正的UI) - MotionKit - TeaCup - RMQ(不仅仅是UI)
我现在想要哪一个是非常有用的,哪一个我应该拒绝.我从头开始一个全新的项目,所以我很灵活选择什么,我想从最有用和最常用的工具开始,让我轻松开发iOS的布局.
你能为RubyMotion推荐一些必备的工具和库吗?
我一直在查看RestKit和GET的工作原理
@client.get("/?amount=5", delegate:self)
Run Code Online (Sandbox Code Playgroud)
有谁知道如何发布POST并收到结果?
文档提到它看起来像这样 -
@client.post("/ask", params:@paramvar, delegate:self)
Run Code Online (Sandbox Code Playgroud)
你怎么封装@paramvar?我已经尝试过它作为数组,哈希甚至是零 - 然而,它们都没有产生任何结果.
假设我有2个控制器A和B.
在AI中有:
def viewDidLoad
super
button = UIButton.buttonWithType UIButtonTypeRoundedRect
button.setTitle "Open B", forState: UIControlStateNormal
button.addTarget(self, action: :open_b, forControlEvents: UIControlEventTouchUpInside)
self.view.addSubview button
end
def open_b
# ?????
end
Run Code Online (Sandbox Code Playgroud)
在BI中有另一种具有自己逻辑的视图,这并不重要.
我想在点击按钮时打开B. 我应该怎么做呢?
对于那些有iOS经验的人来说,这一定是显而易见的,但是我找不到你应该怎么做.任何指针都表示赞赏.Objectve-C中的解决方案是可以接受的,即使我更喜欢使用RubyMotion,也可以获得我的支持.
RubyMotion如何适合iOS游戏开发?
我无法在文档中找到CoreAnimation主题,但我听说有人能够在RubyMotion中使用cocos-2d.
如果您有一些您愿意分享的有用信息,我将非常感谢!
当我在RubyMotion中处理项目时,我经常想出一些我希望在项目之间共享的类的扩展.通常这些扩展很小,并没有真正详细说明.例如:时间类上的小扩展.在项目之间共享这些小扩展的好方法是什么?
我试图动画CALayer的界限,但它不起作用.这是代码:
class CircleView < UIIVew
def initWithFrame(frame)
super
# determine the dimensions
radius = (bounds.size.width < bounds.size.height ? bounds.size.width : bounds.size.height) / 2
# create the circle layer
@circle = CAShapeLayer.layer
@circle.bounds = bounds
@circle.path = UIBezierPath.bezierPathWithRoundedRect(bounds, cornerRadius: radius).CGPath
@circle.fillColor = UIColor.blueColor.CGColor
# add the circle to the view
self.layer.addSublayer(@circle)
shrink
self
end
private
# Applies the shrink animation to the provided circle layer.
def shrink
# determine the bounds
old_bounds = @circle.bounds
new_bounds = CGRectMake(old_bounds.size.width / 2, old_bounds.size.height / …Run Code Online (Sandbox Code Playgroud) 我正在 RubyMotion 中使用某个块,并尝试访问其中在外部声明的实例变量。事实证明我无法从内部访问该变量。我在这里缺少任何明显的解决方案吗?谢谢!
这是代码
@my_var = true
Dispatch::Queue.concurrent.async do
# can't access @my_var here
end
Run Code Online (Sandbox Code Playgroud) 我使用以下方法创建了一个新的RubyMotion项目:
motion create NewMotion
Run Code Online (Sandbox Code Playgroud)
然后我安装了相关的包:
bundle install
Run Code Online (Sandbox Code Playgroud)
现在每当我运行应用程序时,我都会收到错误:
? NewMotion rake
/Users/info/.rvm/gems/ruby-2.0.0-p353/gems/bundler-1.6.2/lib/bundler/runtime.rb:222: warning: Insecure world writable dir /usr/local in PATH, mode 040777
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/universal-darwin13/rbconfig.rb:212: warning: Insecure world writable dir /usr/local in PATH, mode 040777
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
rake aborted!
NoMethodError: undefined method `[]' for nil:NilClass
/Library/RubyMotion/lib/motion/project/xcode_config.rb:87:in `xcode_version'
/Library/RubyMotion/lib/motion/project/xcode_config.rb:99:in `validate'
/Library/RubyMotion/lib/motion/project/template/ios/config.rb:85:in `validate'
/Library/RubyMotion/lib/motion/project/config.rb:115:in `setup'
/Library/RubyMotion/lib/motion/project/app.rb:66:in `config'
/Library/RubyMotion/lib/motion/project/template/ios.rb:81:in `block in <top (required)>'
/Users/info/.rvm/gems/ruby-2.0.0-p353/bin/ruby_executable_hooks:15:in `eval'
/Users/info/.rvm/gems/ruby-2.0.0-p353/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => …Run Code Online (Sandbox Code Playgroud)