I'm currently building an iOS Application for a client and have hit a pretty huge roadblock. I mean, I could write my own UINavigationBar and such but that would cause a lot of issues further down the road.
I have tried everything in my knowledge so far and have spent several hours searching for a solution (overriding the CALayer, using CoreGraphics and pretty much everything else ) and I get the same result. No matter how hard I try to remove the background of the UINavigationBar, it still shows a white background with slight translucency.
I need to have a lot of customisation on the navigation bar (I.E having a gradient going from "blackColor" to "clearColor" and I can't do that if the background of the Navigation Bar refuses to be completely transparent. I have tried copying all of the CALayers from the UINavigationBar layer to a subview I added and it just kept crashing, even when replacing the delegates and superlayer.
I really need help with this. One of the multiple effects I'm trying to achieve are below. (The blue rectangle is not the focus of the image, it's irrelevant.)
To get it completely transparent:
(UINavigationBar.appearance()).translucent = true
(UINavigationBar.appearance()).barTintColor = UIColor.clearColor()
(UINavigationBar.appearance()).backgroundColor = UIColor.clearColor()
(UINavigationBar.appearance()).setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
(UINavigationBar.appearance()).shadowImage = UIImage()
EDIT:
Using iOS 8.3 looking like this:
Or am I missing something?
You are referring to the top Navbar with the back button and Save button right? I'm just confused as to what the blue box on the image is in reference too.
Anyways, this is an extremely hacky approach but could work:
Set the UINavigationBar's alpha to 0. The Back button and Save button will probably also disappear but you could just add labels to the View Controller at the top in the exact same place. The button's should still be functional even though they are "invisible" but the user will still think they are touching them.
Again, very hacky, but you are free to play with the top part of the View then. I'm sure there's a better way to do this but I'm not near a computer with XCode at the moment and can't test it out, and this fix may not even work but I thought I'd offer up a possible temporary solution.
Related
Upon launching my app, I set am "hiding" the tab bar with:
UITabBar.appearance().alpha = 0.0
This is done because some logic is done in order to decide what to display upon launch. It all works, yay! BUT (oh, Stackoverflow time) when the user is all done screwing around with what I have showed them, it is time for the tab bar to reappear. So in a completion block I have (obviously):
UITabBar.appearance().alpha = 1.0
Voila! WAIT NO! Ok so, dispatch_async(dispatch_get_main_queue())? Any luck? NO
Ok fine fine, so let's do a self.view.layoutIfNeeded(). That should do it, right? BONK, NO!
So what's even stranger? Well, when I open a modal on top of this view (with the tab bar still displaying at alpha 0.0 but the code already instructed it to be 1.0 at this point) and then close it, when the view reappears, the tab bar gets redrawn (I assume) and appears with the alpha at 1.0 and showing with all its glory.
So, what gives? And how can I allow the bar to show after the initial state has been drawn to the screen and alpha updated?
Help!
I came across this issue not too long ago, except in the context of the navigation bar. I was curious as well if there exists some sort of means to have the navigation bar redrawn on command. What I observed is if you slid your finger as to move the new page (even slightly), the correct default would appear. Therefore, I concluded this is an issue with redraw not taking place until some sort of interaction occurs. Unfortunately, it seems as though it isn't possible to have this done programmatically.
However, here's the solution I was able to garner that is related your problem:
[Swift 3]
Rather, than using navigationItem.titleView?.tintColor = UIColor.white,
I used:
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white, NSFontAttributeName: UIFont(name: "Copperplate", size: 24.0)]
However, I'm not sure what the correlate is with the tab bar for your scenario. Perhaps, you could figure that out. (I post all of this for those who had my issue and to explain where your issue likely lies).
Now, for your situation. I believe that setting alpha to 0 is likely not the greatest way to approach your problem in the first place.
Give this a try:
UITabBar.appearance().isHidden = true
Hope my solution works or this leads you in the right direction.
Built-in Photo application fades in/out navigationBar when you tap on an image . This way Photo app allows to see it full screen.
How does it do this (fade efect)?
As I understand navigationController?.navigationBar.alpha doesn't work anymore (so you can't animate it this way).
Sharing all my finding.
Complain mode on
Frankly, I feel half pissed/like a dummy that I had to fight a good day to implement simple thing existing in Apple app.
Complain mode off
First of all here is some context. I am working with navigationBar which are provided by navigationController (vs just standalone bars which are manually dropped in your view)
There are several approaches which I found. I will mention all of them (even if I had no success using them)
1) Animate change of alpha of navigationBar
UIView.animateWithDuration(0.1, animations: {
navigationController?.navigationBar.alpha = 0
}, completion: nil)
#rmaddy mention here that it works for him. However, I believe he has a standalone bar (vs a bar managed by navigationController).
I used a tool Reveal to check UI hierarchy and found couple of things.
- There is a navigationBar which is hidden (and navigationController?.navigationBar is referencing it). So you can change alpha to your hearts joy, but these changes won't be visible.
There is however another navigationBar . I assume it's referenced in some private members of navigationController (let's call it private navigationBar). It's visible and that's what is displayed at the top of your view.
2) Use setNavigationBarHidden:animated:
This is a standard way to hide/show navigation bar. It's animated different way (it slides/up and down). However, if it's ok for you, just go with this is, because it's simple and clean.
navigationController?.setNavigationBarHidden(true, animated: true)
Additionally you can wrap it in UIView.beginAnimations, UIView.commitAnimations to animate it together with some other stuff (to make it smoother)
3) Animate change of alpha of private navigation bar.
This worked for me:
let privateNavigationBar = self.superview?.superview?.superview?.superview?.superview?.superview?.subviews[1]
UIView.animateWithDuration(0.1, animations: {
privateNavigationBar.alpha = 0
}, completion: nil)
I am going way up through the hierarchy to get a view which contains private navigationBar (which is second subview for that view).
However, this approach has multiple downsides:
I believe # of superviews? depends on your app hierarchy (vs you are using split view and so on). I think you can generalize or may be you just walk the whole hierarchy to find non hidden UINavigationBar to solve this.
I have a feeling that Apple may frown at this (your app be not accepted to AppStore)
4) Make navigationBar transparent and set background image to be transparent and change alpha channel on it.
I can't find where I read about this idea. There was couple of mentioning.
There is Apple example app which shows how to customize NavigationBar, including making it transparent.
It's interesting that this example app works for me (the navigation bar is transparent in it). However, when I tried this code in my app it didn't work (I still didn't figured out what is going on with this). As usual there are bunch of variables (may be something in Info.plist, also they subclass NavigationController, also may be something in view hierarchy)
5) Adding standalone navigationBar
You can hide a bar provided by navigationController. Add your own to the UIView, wire it to #IBOutlet and use alpha animation on it (most likely that's what #rmaddy was referring too).
I checked and this is work.
This approach is used in this tutorial.
However, it has a downside:
I believe it won't handle well rotation, increase of statusbar height while call or GPS
Each time when I see a code like this (written in the article) I know that there will be problems with resizing: CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), 64.0)
You can potentially replace it with constrains. I went this route, but stumble upon some issues.
6) Other methods
I saw two more methods. I don't know whether they will work or what will be downsides:
One of them in this question: How to hide/show status bar and navigation bar by fading in/out at the same time like the Photos app in iOS 7?
And this answer: https://stackoverflow.com/a/18063898/422080
I have a pale green coloured tableview and when I enter Edit mode the reorder controls on the right edge are almost invisible. Can anyone tell me how to either use my own image for this or darken the system image?
I'm answering my own question because I don't want anyone else wasting time on this. You can't change this... I have resorted to switching my TableView's background colour back to white when I enter editing mode. This is yet one more horrible compromise but c'est la vie! Same with the right chevron in the accessoryView. It would seem obvious that one might be able to set this to the colour of their choice. Not so. The only way I found for doing this, simply darkening the chevron, was to subclass a UIControl and write my own drawRect method. Apple has an awful load of money yet cannot appear to employ enough programmers to keep a handle on this sort of very, very simple UI stuff. It appears that the bigger the libraries get the less we are able to actually do with them.
I'm currently working on an iOS app that is pretty much supposed look and work like an already existing android app.
As a part of that, I'd like to make the top navigation look the same, but since iOs devices do not provide a hardware or software integrated back button, I'd also like to keep the back button navigation that's common to iOs apps.
I've tried numerous attempts to achieve it, but I'll stick with the latest I'm working on since it looks the most promising. I've started to work on a custom UINavigationBar class that overrides the initWithCoder: and layoutSubviews: methods. The result is as follows:
As you can see, the back button now overlaps the application icon. What I'm looking for is a way to make the button and the text to scale into the space right of the application icon. I've tried to handle this in layoutSubviews: but the superclass logic appears to be rather complex, I was not able to reproduce it's functionality (in particular it seems to be working with some private variables I don't have access to).
I also tried manipulating self.frame before calling [super layoutSubviews] but apart from endless loops I was not able to achieve anything in that direction.
I'd be happy if anyone could point me into the right direction.
If I understand your problem correctly, I think you could do this by adding a custom titleView to the UINavigationItem, and have an image view (on the left side for the icon) and a label (for the title) as subviews. This would replace the default title.
I am newbi to iphone apps as well as to this forum.
I want to place a background texture for my UIView that should cover the whole iPhone screen. I have controls placed on this view currently. Later on, I would like all my controls to be transparent, so user must be able to work with controls, but not see anything except its text.
Here is what I tried:
Created a UIView derived view - with simple background color, no image
Placed my controls - UIButtons, labels
Programmed all of them correctly to reflect my game logic
Now I have a change of my mind. I think its lot better to have a background texture for my view, as well as controls.
1) I tried things mentioned at: Adding A Background Image In Interface Builder
but this covers my UI controls.
2) Through Interface builder, I tried drag-dropping the texture image onto my view (which in turn, probably, created a UIImageview with background image = my texture). But that again hid every of my past work.
Then I started playing with alpha value (0.1, 0.8 etc) - it gives me some result, but I am no longer able to design my controls. Nor I am able to click (=touch) them at runtime anymore.
Please give me a method that will not disrupt my work so far (I hate redoing all the outlet wiring of my controls), but still allow me to achieve my goal.
Forgive me if I asked too silly thing, or did not search enough. This is my first question, and will be glad to try any helpful solution!
Many thanks!
How about:
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"texture.png"]];