2

I just want to set a background image on a screen for a placeholder. What is the quickest, easiest, simplest way to do that? Everything I've tried does not seem to work.

I should mention that this is in RedPotion so I already have access to RMQ.

Andrew
  • 227,796
  • 193
  • 515
  • 708

1 Answers1

2

I do exactly this in RedPotion for my RubyTrivia app. Simply set your root_view style for your given RedPotion stylesheet. In this case I'm setting the background image to an image resource.

# In an RMQ Stylesheet
def root_view(st)
  st.background_image = image.resource('retina_wood')
end

# In a ProMotion Screen
def on_load
  find(view).style {|st| st.background_image = image.resource('retina_wood') }
end

Note that the RMQ implementation of background_image= sets the background to be a tiling (repeating) background image. So if you want to fill the screen, you will want to use a different approach as it will look differently on different sized screens. My RubyTrivia app is open source, so please enjoy! https://github.com/IconoclastLabs/rubytrivia

Andrew
  • 227,796
  • 193
  • 515
  • 708
Gant Laborde
  • 6,484
  • 1
  • 21
  • 30
  • Is there a way to do this without creating a style sheet class? – Andrew Jun 03 '15 at 02:38
  • if you're using redpotion, you should embrace stylesheets when possible. If you take a look at what RMQ is doing there, you can simply do that in your `on_load` to bypass the need of a stylesheet: https://github.com/infinitered/rmq/blob/master/motion/ruby_motion_query/stylers/ui_view_styler.rb#L230-L232 – Gant Laborde Jun 03 '15 at 03:21
  • 1
    O btw, you can style anything without using a class. You can do `rmq(self).style { |me| me.background_image = image.resource('taco') }` which is still RMQ styles, but no class. – Gant Laborde Jun 03 '15 at 03:22
  • Oh awesome, that's exactly what I was looking for. I'm using style sheets in other parts of the app but in this case I was just looking for a one-liner. – Andrew Jun 03 '15 at 03:26
  • 2
    Also, thanks for open-sourcing your app. I'm learning a lot by simply browsing the source. =] – Andrew Jun 03 '15 at 03:56