Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Change a ui.NavigationView bar color
-
So I tried it and got an error... Noneobject has type superview.
-
I have figured out its because I placed it before the present. But if i place it after it doesn’t change
-
Hi. The method I wrote, that Phuket2 mentioned, was to change the title bar color, it probably won't work for your Navigation bar without modification.
I just put some code that JonB wrote into a method - he really did the heavy lifting.
-
If your navigationview is n:
ObjCInstance(n).navigationController().navigationBar().backgroundColor=UIColor.redColor()
etc
-
For some reason this fails to change the color, but no errors are given.
-
@JonB said:
ObjCInstance(n).navigationController().navigationBar().backgroundColor=UIColor.redColor()
sorry, i meant
ObjCInstance(nav).navigationController().navigationBar()._backgroundView().backgroundColor=UIColor.redColor()
-
Still nothing changes. I’m not sure what I’m doing.
-
import ui from objc_util import * v=ui.View(frame=(0,0,576,576),bg_color='blue',name='view') nav = ui.NavigationView(v,name='nav view') v.left_button_items = [ui.ButtonItem(image=ui.Image.named('ios7_film_256'))] ObjCInstance(nav).navigationController().navigationBar()._backgroundView().backgroundColor=UIColor.redColor() nav.present('landscape')
does this give you a white "nav view" bar on top, with a red "view" bar, followed by a blue main view?
if not, tryimport ui from objc_util import * v=ui.View(frame=(0,0,576,576),bg_color='blue',name='view') nav = ui.NavigationView(v,name='nav view') v.left_button_items = [ui.ButtonItem(image=ui.Image.named('ios7_film_256'))] def changecolor(): ObjCInstance(nav).navigationController().navigationBar()._backgroundView().backgroundColor=UIColor.redColor() nav.present('landscape') ui.delay(changecolor, 2)
-
The second works. So apparently there is no way to change it before presenting?
-
@robertiii, to me appears you have to present it first. I just did some tests, and it appears to me it's impossible just using Pythonista ui methods to create an invisible view. Not sure why @omz choose not to have a param in the present method to allow the view to be hidden on presentation. Could be some technical issue. I did try setting the views hidden attr to True be presenting. It does not work. But interestingly, if you set the view's bg_color to say 'blue' and have the views hidden attr set to True, you dont see the bg_color when the views presented.
I also tried the same with a second view after the first view had be created and presented on the screen. Same results. I tried this just in case it made a difference if there was at least one view presented on the screen or not. Maybe someone has more insight to this, -
you might try wrapping changecolor with a @on_main_thread. I am pretty sure i was able to change color prior to present, but maybe present is changing some defaults.
@phuket
present does not automatically set hidden=False (panel does, sheet does not). not being presented (no parent) and being hidden are two completely separate things.