Background/header for Formotion forms in RubyMotion

Neeraj Singh

Neeraj Singh

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.

class LoginViewController < Formotion::FormController

  def viewDidLoad
    super
    view = UIView.alloc.init
    view.backgroundColor = 0x838E61.uicolor
    self.tableView.backgroundView = view
  end
end

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:

header_image = UIImage.imageNamed('header_image_name.png')
header_view = UIImageView.alloc.initWithImage(header_image)
self.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.

If this blog was helpful, check out our full blog archive.

Stay up to date with our blogs.

Subscribe to receive email notifications for new blog posts.