Created
June 16, 2014 05:07
-
-
Save jalquisola/0fd47a9f8264fe819891 to your computer and use it in GitHub Desktop.
Customize navigation bar using Rubymotion + ProMotion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SampleScreen < Promotion::Screen | |
title "Sample" #pass empty string if you dont want to display title in nav_bar | |
def on_load | |
customize_nav_bar | |
end | |
private | |
def customize_nav_bar | |
#set nav bar buttons using ProMotion | |
set_nav_bar_button :left, {action: :go_to_browse, image: 'btn_back'.uiimage} | |
nav_bar = self.navigationController.navigationBar | |
#change tintColor | |
nav_bar.tintColor = UIColor.whiteColor # if you are using sugarcube, you can use :white.uicolor | |
#add background image | |
nav_bar.setBackgroundImage('some_image_background'.uiimage, forBarMetrics: UIBarMetricsDefault) # see rubymotion docs: http://www.rubymotion.com/developer-center/api/UINavigationBar.html | |
#add some buttons with image | |
btn_1 = UIBarButtonItem.alloc.initWithImage('btn_1'.uiimage, style: UIBarButtonItemStylePlain, target: self, action: 'btn_1_clicked') | |
btn_2 = UIBarButtonItem.alloc.initWithImage('btn_2'.uiimage, style: UIBarButtonItemStylePlain, target: self, action: 'btn_2_clicked') | |
self.navigationItem.rightBarButtonItems = [btn_1, btn_2] | |
end | |
def go_to_browse | |
open BrowseScreen.new | |
end | |
def btn_1_clicked | |
#add your code here | |
end | |
def btn_2_clicked | |
#add your code here | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment