Skip to content

Instantly share code, notes, and snippets.

@burkeholland
Last active August 29, 2015 14:18
Show Gist options
  • Save burkeholland/b4580106f11d29236218 to your computer and use it in GitHub Desktop.
Save burkeholland/b4580106f11d29236218 to your computer and use it in GitHub Desktop.
Navigation / Status Bar Tweaks

Tweaking The Navigation / Status Bar In NativeScript

exports.loaded = function(args) {

  var page = args.object;
  page.bindingContext = feedModel;

  var controller = frameModule.topmost().ios.controller;
  var navigationBar = controller.navigationBar;
  var navigationItem = controller.visibleViewController.navigationItem;
  
  try {

    /*  Create bar button item
        
        first argument is what icon to show:
        
        UIBarButtonSystemItemDone,
        UIBarButtonSystemItemCancel,
        UIBarButtonSystemItemEdit,
        UIBarButtonSystemItemSave,
        UIBarButtonSystemItemAdd,
        UIBarButtonSystemItemFlexibleSpace,
        UIBarButtonSystemItemFixedSpace,
        UIBarButtonSystemItemCompose,
        UIBarButtonSystemItemReply,
        UIBarButtonSystemItemAction,
        UIBarButtonSystemItemOrganize,
        UIBarButtonSystemItemBookmarks,
        UIBarButtonSystemItemSearch,
        UIBarButtonSystemItemRefresh,
        UIBarButtonSystemItemStop,
        UIBarButtonSystemItemCamera,
        UIBarButtonSystemItemTrash,
        UIBarButtonSystemItemPlay,
        UIBarButtonSystemItemPause,
        UIBarButtonSystemItemRewind,
        UIBarButtonSystemItemFastForward,
        UIBarButtonSystemItemUndo,
        UIBarButtonSystemItemRedo,
        UIBarButtonSystemItemPageCurl */
    var shareItem = new UIBarButtonItem(9, null, null);

    // set item color with system constant
    shareItem.tintColor = UIColor.whiteColor();
    
    // add item to navigation bar
    var actionButtonItems = [shareItem];
    navigationItem.rightBarButtonItems = actionButtonItems;

    // hide back button
    navigationItem.setHidesBackButtonAnimated(true, false);

    // change bar color, this time with RGB instead of system constant
    navigationBar.barTintColor = UIColor.colorWithRedGreenBlueAlpha(0, 0.24, 0.45, 1);
    
    // change title color
    navigationBar.titleTextAttributes = new NSDictionary([UIColor.whiteColor()], [NSForegroundColorAttributeName]);

    /*  change status bar style
        UIStatusBarStyleDefault,
        UIStatusBarStyleLightContent,
        UIStatusBarStyleBlackTranslucent,
        UIStatusBarStyleBlackOpaque */
    navigationBar.barStyle = 1;
  }
  catch (e) {
    alert(JSON.stringify(e));
  }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment