iOS Question Change NavBar Text Color

jcesar

Active Member
Licensed User
Hi

How can i change the navbar text color ?

This code change the background color:

B4X:
Dim no As NativeObject = NavControl
    no.GetField("navigationBar").RunMethod("setBarTintColor:", Array(no.ColorToUIColor(Colors.RGB(0,128,128))))
If I change to SetTintColor, I can change the button font color.

But I haven´t found a method to change the Title color.
 

Turbo3

Active Member
Licensed User
Looks like you would need to use "setTitleTextAttributes:" but you need to provide more than just the color so the Array of data is more complicated.
 

Erel

Administrator
Staff member
Licensed User
Here:
B4X:
Private Sub Application_Start (Nav As NavigationController)
   NavControl = Nav
   Page1.Initialize("Page1")
   Page1.RootPanel.LoadLayout("1")
   NavControl.ShowPage(Page1)
   Page1.Title = "Title"
   SetTitleColor(Nav, Colors.Red)
End Sub

Sub SetTitleColor(nav As NavigationController, clr As Int)
   Dim attributes As NativeObject
   attributes = attributes.Initialize("B4IAttributedString").RunMethod("createAttributes::", _
     Array(Font.CreateNew(18), attributes.ColorToUIColor(clr)))
   Dim no As NativeObject = nav
   no.GetField("navigationBar").RunMethod("setTitleTextAttributes:", Array(attributes))
End Sub
 

Ramezanpour

Active Member
Licensed User
Here:
B4X:
Private Sub Application_Start (Nav As NavigationController)
   NavControl = Nav
   Page1.Initialize("Page1")
   Page1.RootPanel.LoadLayout("1")
   NavControl.ShowPage(Page1)
   Page1.Title = "Title"
   SetTitleColor(Nav, Colors.Red)
End Sub

Sub SetTitleColor(nav As NavigationController, clr As Int)
   Dim attributes As NativeObject
   attributes = attributes.Initialize("B4IAttributedString").RunMethod("createAttributes::", _
     Array(Font.CreateNew(18), attributes.ColorToUIColor(clr)))
   Dim no As NativeObject = nav
   no.GetField("navigationBar").RunMethod("setTitleTextAttributes:", Array(attributes))
End Sub
how to use this for code module with multiple pages ? (with Tabcontroller)
 
Top