Change color of translucent black UINavigationBar - uinavigationcontroller

I stumbled upon this many times, never found a solution.
A UINavigationController's navigationBar can be set to black translucent like:
self.navigationController.navigationBar.barStyle=UIBarStyleBlackTranslucent;
Also, there is a translucent property in UINavigationBar, the docs say:
When YES, the navigation bar is drawn with partial opacity, regardless
of the bar style. The amount of opacity is fixed and cannot be
changed. It is permissible to set the value of this property when the
navigation bar is being managed by a navigation controller object.
I tried
self.navigationcontroller.navigationBar.tintColor=[UIColor blueColor];
self.navigationcontroller.navigationBar.translucent=YES;
and a thousand variations: Setting the translucent property first, setting it in the AppDelegate and in the ViewController, setting the barstyle first.
The result is always the same: No transparency. Hence my question:
Is it really possible to change the color of a translucent UINavigationBar to something different than black (preferably within a UINavigationController)?.
I hope there is a review-safe solution.
Thanks, m

Once you know it, it's fairly simple:
self.navigationController.navigationBar.tintColor = [UIColor blueColor];
self.navigationController.navigationBar.alpha = 0.7f;
self.navigationController.navigationBar.translucent = YES;
The translucent property seems only to determine wether the main view should be visible under the navigation bar, and resizes the view appropiately.

To mimic more accurately the translucent effect, meaning that only the background of the navbar is translucent, and the buttons, title and everything else are opaque, you can do like this:
self.navigationController.navigationBar.translucent = YES;
[(UIView*)[self.navigationController.navigationBar.subviews objectAtIndex:0] setAlpha:0.7f];

At least in iOS 6 on an iPhone 4S, you can make a colored translucent navigation bar like this:
self.navigationController.navigationBar.tintColor = [UIColor blueColor];
self.navigationController.navigationBar.translucent = YES;
The alpha setting doesn't seem to be necessary anymore. This also leaves my title bright white and my buttons opaque.

Here is the solution:
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:3.f/255.f green:8.f/255.f blue:61.f/255.f alpha:1]];
self.navigationController.navigationBar.translucent = YES;
self.navigationController.navigationBar.barTintColor = [UINavigationBar appearance].barTintColor;

Related

Setting background color of system background for widgets, on a QGraphicsScene

In my QGraphicsScene, I would like to set the background brush to the default widget background - but I can't get it.
Kinda like, for my QGraphicsView,
setBackgroundRole(QPalette::Window);
or
setBackgroundBrush(palette().background().color());
(but setting this I see nothing happening)... I also see nothing happening if I set the view color to a bright red).
So I thought I must set color directly on the QGraphicsScene.
For the QGraphicsScene I am trying all sort of combinations like
setBackgroundBrush(QPalette::color(QPalette::Background));
Nothing will even build, seems I require an object (? a widget ?) - but my scene may not have a widget parent... and all I want is a default palette, I thought there would be a generic way to get that color without having a widget ?
On the scene, this will work...
setBackgroundBrush(Qt::red);
No clue why the view won't show color (even if I set on the view, red brush and on the scene transparent).
You may retrieve the QApplication's current style using the static method style(). From there, you may access the QStyle's standard palette using standardPalette(). Use QPalette's brush method to get a brush for a given ColorRole. Putting it all together you get...
QApplication::style()->standardPalette().brush(QPalette::Background)
This may not be the color you are expecting. Check out the documentation on http://doc.qt.io/qt-4.8/qpalette.html, and try different ColorRole values until you find what you're looking for.
Create a temporary widget instance just to access its palette and get the background color:
QColor bgColor = QWidget().palette().background().color();
But I think you should set the background color in the QGraphicsView widget. You can do that by changing its stylesheet. Something like:
QColor bg = ui->graphicsView->palette().background().color();
ui->graphicsView->setStyleSheet(QString("background-color:") + bg.name(QColor::HexArgb));
Setting a transparent background also works.

How can I set the backgroundColor of a WKInterfaceController programmatically?

I couldn't find any way of changing the overall background color of the Watch app interface programmatically.
I therefore tried creating a fullscreen WKInterfaceGroup and changing the backgroundColor of that.
centralGroup.setBackgroundColor(UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0))
However, I still have unfilled rounded corners and lines on borders.
Is there any way to achieve my goal, of an edge-to-edge background color that fills the screen?
While you can set a background color for a WKInterfaceController in the storyboard, there is no API that lets you programmatically set it in the present Xcode 6.2 beta 3.
However, you can create a full screen WKInterfaceGroup and set the color of that programmatically. If you also setCornerRadius: to 0 you get the following result:
Clearly, there are still black lines at the edges here. The other possibility was that setting a solid color image as the background might perhaps scale to fill the full screen with one of the scaling options, but I tested this and the result is identical to the above.
However, it is important to consider the hardware this will be running on. Apple have said more than once in their public statements about the Watch that the intersection between the laminated screen and the edges is so seamless that you essentially can't tell where the screen ends and the edges begin. Taking this at face value, as long as you set the background color of the WKInterfaceController to clear or black in interface builder, so that these edges are black to match the screen surround, then these black lines should be invisible to the end user and are something you can safely ignore.
This is how I done it:
Add WKInterfaceGroup and setCornerRadius to 0
Go to WKInterfaceController Attribute Inspector and change Left/Right insets to 0 (Fig.1) (This will remove the extra black line on the left & right side)
Change the color of the WKInterfaceGroup to whatever you want :)
Fig.1
Change insets of Your WKInterfaceController to custom and set all to 0. Also, change corner radius of group to 0 too. Enjoy.
Try changing the corner radius of the WKInterfaceGroup to 0. You can use setCornerRadius: to change the corner radius.

iOS 7 UIToolBar color

I have a toolBar in a tableView under iOS 7. It has this default blur and I just want to paint it black.
I am doing this:
self.navigationController.toolbarHidden = NO;
self.navigationController.toolbar.tintColor = [UIColor blackColor];
self.navigationController.toolbar.barTintColor = [UIColor blackColor];
self.navigationController.toolbar.backgroundColor = [UIColor blackColor];
self.navigationController.toolbar.translucent = NO;
With no success... The toolbar still has a "clearColor" and is still translucent.
Am I missing something?
EDIT: I am not using storyboards. The view is not loaded from Nib.
EDIT: I started a new project, and the it works. Still I have to figure out why it is not working in the first project!
if you are using storyboards you can turn off Translucent and change the style to black in the attributes inspector tab (fourth across just before the ruler) in the utilities panel
You need to set it on the UINavigationController. The toolbar is a property of UINavigationController, so you need to set it there. If you are not using Storyboard, you need to create a subclass.
I'm using storyboard. In Storyboard select the UINavigationController (not the embedded view!) and switch to the little shield in the right view (4th element). Then select "shows toolbar" and now you can select the toolbar and set the color.
Hope it helps!

UISearchBar in UINavigationBar changes width when rotating orientation

This is driving me crazy. I am creating a splitview app on iPad.
I have created a searchBar inside the UINavigationBar - something like this...
UISearchBar *searchBar = [[UISearchBar alloc] initWitFrame:CGRectZero];
[searchBar setPlaceHolder:#"Search"];
[searchBar sizeToFit];
[searchBar setDelegate:self];
[self.navigatioItem setTitleView:searchBar];
this works just fine for me displaying the UISearchBar like this...
I also have this UIBarButtonItem set to show Master navigation controller in sidepane.
The problem happens when the device rotates to landscape and the UIBarButtonItem gets hidden. Then the searchBar appears like this...
there is some space on sides which appears to be there since the barButtonItem got hidden and the size of search bar couldn't be updated.
Furthermore, when I rotate the device again, here's what happens to UISearchBar
How can I update the size of searchbar once it has been added to UINavigationBar. Even using autoResizingMask does not work.
searchBar.autoResizingMask =UIViewAutoresizingFlexibleWidth;
What am I doing wrong over here?
I had about the same problem (it wasn't searchbar, but some UIView), and that's how I solved it:
Try creating it with fixed size that won't change. I mean if your navbar minimum size is (for example) 320pt, and barbutton is about 30pt, and you need searchbar to be placed right in the middle (which, BTW is not standart, AFAIK), you'd have to make it 320 - (30+10)*2 = 240pt. Searchbar would be placed right in the middle and will have enough place left free.
This way it will neither change it's size, nor it will affect other items.
Or I would suggest you placing it at right position, not in the middle.
Hope it helped.

Flex 3 - Rounded bottom corners on a window?

I'm making a flex 3.5a/air2 application and I've made a popup window but I can't seem to get its bottom corners rounded. Setting cornerRadius seems to only affect the top corners.
There doesn't seem to be a roundedBottomCorners property like there is for panels, and adding a controlbar with a cornerRadius also has no effect.
I'm sure this is a very simple problem but would really appreciate any help as I can't find the answer on google or after searching on here!
If you can give up window header (and paint it yourself), try to make transparent window (with transparent background) and construct it from controls you need. I'm sure you can get window of any shape this way.
Ended up making the window transparent and setting showFlexChrome to false. Then using a container I was able to get rounded corners.
It didn't help my other problem which was trying to get a glow effect around the window and still being able to resize it.. for that I had to override the mouseDownHandler from the window class so I could modify the drag locations to the container canvas. What a pain!

Resources