Navigation color

I have been trying to get Jason’s code from a post about 5 months ago working but when I call the method it keeps rejecting the myViewName.

How do I reference the name

sub setNavBarColor(v as iOSView, barColor as color, buttonColor as color, translucent as boolean = false)

declare function NSClassFromString lib “Foundation” (classname as CFStringRef) as ptr
declare function keyWindow lib “UIKit” selector “keyWindow” (obj_ref as ptr) as ptr
declare function sharedApplication lib “UIKit” selector “sharedApplication” (obj_ref as ptr) as ptr
declare function rootViewController lib “UIKit” selector “rootViewController” (obj_ref as ptr) as ptr
declare function navigationBar lib “UIKit” selector “navigationBar” (obj_ref as ptr) as ptr

declare function navigationController lib “UIKit” selector “navigationController” (viewController as ptr) as ptr
dim navigationControllerRef as ptr = navigationController(v.ViewControllerHandle)
dim sApp as ptr = sharedApplication(NSClassFromString(“UIApplication”))
dim navBar as ptr = navigationBar(navigationControllerRef)

declare sub setTintColor lib UIKitLib selector “setTintColor:” (id as ptr, UIColor as Ptr)
setTintColor navBar, new UIColor(buttonColor)

declare sub setBarTintColor lib UIKitLib selector “setBarTintColor:” (id as ptr, UIColor as Ptr)
setBarTintColor navBar, new UIColor(barColor)

if translucent then
declare sub setTranslucent lib UIKitLib selector “setTranslucent:” (id as ptr)
setTranslucent navBar
end
end sub
Call it like this:

SetNavBarColor myViewName, myBarColor, myButtonColor

Your code actually works but can’t be called in the View.Open event.

Using Xojo.core.Timer.CallLater with a 1ms delay will do the trick

EDIT:
Calling directly:

SetNavBarColor myViewName, myBarColor, myButtonColor

In the View.Activate event also works.
It is better to place the code in Activate if you need to change the color when switching views

Hi Jeremie,
I have it in the Activate event but don’t know how to call the myviewname?

The Name of my view is MainMenuView but that isn’t accepted as a parameter… suggestions?

Sorry, I should have corrected the code.

Use self instead of myViewName