Back to Blog

Background/header for Formotion forms in RubyMotion

on June 8, 2013

Formotion for Rubymotion makes it a breeze to create views with forms. I am building a rubymotion app and my login form uses formotion. I needed to set background color for my form and here is how you can set a background color for a form created using Formotion.

1class LoginViewController < Formotion::FormController
2
3  def viewDidLoad
4    super
5    view = UIView.alloc.init
6    view.backgroundColor = 0x838E61.uicolor
7    self.tableView.backgroundView = view
8  end
9end

After the login view is done loading, I'm creating a new UIView and setting its background color. Then this UIView object is set as the background view to formotion's table view.

Setting header image

If you want to add some branding to the login form, you can add a image to the form's header by adding the below code to viewDidLoad:

1header_image = UIImage.imageNamed('header_image_name.png')
2header_view = UIImageView.alloc.initWithImage(header_image)
3self.tableView.tableHeaderView = header_view

We are creating a UIImageView and initializing it with the image we want to show in the header. Now, set the tableview's tableHeaderView value to the UIImageView we created.


You might also like

If you liked this blog post, check out similar ones from BigBinary