Setting UINavigationbar properties in viewDidLoad does nothing - iphone

I've tried setting the style of the UINavigationbar to be a translucent style in the viewDidLoad method of my controller. But nothing is changed. Why?
I set the property using the standard code like
self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;

According to Apple documentation:
UIBarStyleBlackTranslucent is deprecated. Use UIBarStyleBlack and set the translucent property to YES instead.

just had the same issue - the apple doc is a little vague - here's the solution
navigationController.navigationBar.barStyle = UIBarStyleBlack;
navigationContoller.navigationBar.translucent = YES;

UIBarStyleBlackTranslucent
Deprecated. Use UIBarStyleBlack and set the translucent property to YES instead.
Available in iPhone OS 2.0 and later.
Declared in UIInterface.h.

Related

View got hidden below UINavigationBar iOS 7

Earlier, I was using iOS 6.1 for my project. Recently I have switched to iOS 7. For, a lot of changes I knew, I updated my code.. But I have observed a strange behavior. My view on every screen gets hidden below navigation bar. Repositioning view solves the problem for iOS7, but creates problems for older iOS versions.
Can anyone explain me, what is the reason and why does it happen?? What has been changed in iOS 7 that's causing this problem??
Any help would be appreciated..
Try navigationBar.translucent = NO;, It is YES by default in iOS7.
It is also good to take a look on this part of UINavigationBar documentation:
New behavior on iOS 7. Default is YES. You may force an opaque
background by setting the property to NO. If the navigation bar has a
custom background image, the default is inferred from the alpha values
of the image—YES if it has any pixel with alpha < 1.0 If you send
setTranslucent:YES to a bar with an opaque custom background image it
will apply a system opacity less than 1.0 to the image. If you send
setTranslucent:NO to a bar with a translucent custom background image
it will provide an opaque background for the image using the bar's
barTintColor if defined, or black for UIBarStyleBlack or white for
UIBarStyleDefault if barTintColor is nil.
Edit:
Setting 'navigationBar.translucent' value causes exception if you run project in devices/simulators having older iOS versions.
So you can add a version check like this:
float systemVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
if (systemVersion >= 7.0)
{
navigationBar.translucent = NO;
}
Another option would be to set:
vc.edgesForExtendedLayout = UIRectEdgeNone;
Swift 3:
vc.edgesForExtendedLayout = []
You can stop your views going under the navigation bar, in your viewController:
self.edgesForExtendedLayout = UIRectEdgeNone;
Swift 3+:
self.edgesForExtendedLayout = []
If you do not need translucent navigation bar in your app you can fix this on iOS7 and iOS6 without code changes.
In storyboard select your navigation controller and then open "Attributes Inspector". Then under "Simulated Metrics" set "Top Bar" to some value but not to "translucent":
Now your views on iOS6 and iOS7 will have the same positioning as before.
Point #7 on this list does the trick. You still have to wrap it in iOS 7-checking code like #null's answer:
float systemVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
if (systemVersion >= 7.0) {
viewController.edgesForExtendedLayout = UIRectEdgeNone;
}
The whole article is useful to those transitioning to iOS 7.
Use this property for your VC, in-order to avoid overlap of ur statusbar with your VC Swift :
self.edgesForExtendedLayout = []
Objective C
self.edgesForExtendedLayout = UIRectEdgeNone;
Look up this key: UIViewControllerBasedStatusBarAppearance.
It's used in your app's info PLIST file and will come up as:
View controller-based status bar appearance
This will allow you to control the status bar's appearance. There's a bunch of API changes for status bars, go have a look in the documentation for new UIViewController methods such as
- (void)prefersStatusBarHidden;
For me the best way for transparent Navigation Bar is to change the shadowImage and backgroundImage of the bar.
navigationController?.navigationBar.isTranslucent = true
navigationController?.navigationBar.backgroundColor = nil
navigationController?.navigationBar.setBackgroundImage(UIImage(named: "navBarBackground")?.resizableImage(withCapInsets: .zero, resizingMode: .stretch), for: .default)
navigationController?.navigationBar.shadowImage = UIImage()
In Swift 2.2, use
self.edgesForExtendedLayout = .None

UINavigationBar change tint color in Category

I know I can change the tint color of navigation bar in xib file easily. But the problem is that if i have to change in a lot of places.
Hence i tried using the (fancy) category and overriding the draw rect method.
#import "UINavigationBar+customTint.h"
#implementation UINavigationBar (customTint)
-(void)drawRect:(CGRect)rect{
self.tintColor = [UIColor redColor];
}
#end
I have imported it in the corresponding view controller as well. What am i doing wrong?
Whats the right way of doing it?
THanks in advance
That is one way of doing it. It would probably just be easier in you ViewController where ever you need to change it add the line:
self.navigationController.navigationBar.tintColor = [UIColor redColor];
Using a category for just one line is probably overkill.
EDIT:
If you do want to use a category, you may need to call setNeedsDisplay on the navigation bar. or override another method and call it.
Something like ,
[self.navigationController.navigationBar setNeedsDisplay];
Also according to Apple's documentation
In iOS 5, the UINavigationBar, UIToolbar, and UITabBar implementations have changed so that the drawRect: method is not called unless it is implemented in a subclass. Apps that have re-implemented drawRect: in a category on any of these classes will find that the drawRect: method isn't called. UIKit does link-checking to keep the method from being called in apps linked before iOS 5 but does not support this design on iOS 5 or later.
Apps can either:
Use the customization API for bars in iOS 5 and later, which is the preferred way.
Subclass UINavigationBar (or the other bar classes) and override drawRect: in the subclass.
The best way to therefore go about this would be to place this in your ApplicationDidFinishLaunching
NSString *reqSysVer = #"5.0";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending)
[[UINavigationBar appearance] setTintColor:myColor];
And also leave your DrawRect, so that it will work on iOS less than 5
If you're using iOS5 then the correct way to do it is to use the UIAppearance proxy.
[[UINavigationBar appearance] setTintColor:myColor];
Details here: https://developer.apple.com/library/ios/#documentation/uikit/reference/UIAppearance_Protocol/Reference/Reference.html

custom UINavigationBar background in MFMailComposeViewController

I have a need to use a custom background for the UINavigationBar in a MFMailComposeViewController. Previously I was using a category on UINavigationBar to achieve this throughout my app, but Apple specifically requests that you do not do this. Additionally this may or may not work in future versions of iOS that are currently under NDA.
I am now using a subclass of UINavigationBar to achieve the look I'm after in the rest of the app, but I can't see any way to use this with the MFMailComposeViewController. Any ideas?
Note: I'm aware of methods to do this in a future version of iOS, but this needs to be built against a current version (4.3) of the SDK.
I just ran across this -- you can dynamically inject the class a view controller uses using object_setClass.
#import <objc/runtime.h>
object_setClass(mailController.navigationBar, [YourNavigationBarSubClass class]);
You can customize the nav bar's titleView with a custom view using the code below. Expanding upon this idea, you may be able to resize the titleView to cover the entire navigation bar and use a custom background in that to simulate a custom navbar background.
The only possible sticky part I can think of is that you need to make sure the titleView sits behind the buttons in the toolbar.
Once you have your MFMailComposerViewController reference, here is the code to customize the titleView:
[self presentModalViewController:controller animated:YES];
UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(//set size to navbar size)];
[backgroundView setBackgroundColor:[UIColor colorWithPatternImage://your custom image ]];
controller.topViewController.navigationItem.titleView = backgroundView ;
[controller release];
The mail composition interface itself is not customizable and must not be modified by your application.
check apple reference for more info...
http://developer.apple.com/library/ios/#documentation/MessageUI/Reference/MFMailComposeViewController_class/Reference/Reference.html
but we can customizable the mail composition as given oin the above answer....
After some hacking and testing, still not manage to customize the button. But this is the closest I can get, by setting the tint color of mail controller.
Try accessing them through mailController.navigationBar.items, which is an array of the bar items.
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
mailController.mailComposeDelegate = self;
mailController.navigationBar.tintColor = [UIColor brownColor];
Although it would be nice to get more control over the appearance, I don't think there is a clean method. When you cant change it...hide it:
NSDictionary *attributes = #{NSForegroundColorAttributeName: [UIColor clearColor]};
[[UINavigationBar appearance] setTitleTextAttributes:attributes];

iPhone SDK 3.0 in-app email - changing navigation bar tint color

My App uses the iPhone SDK 3.0's new in-app email feature.
I want to change the tint color of the email UI to black and make it translucent.
I tried the following code,
/*
picker.navigationController.navigationBar.tintColor = [UIColor blackColor];
picker.navigationController.navigationBar.translucent = YES ;
*/
But it's changing the color of the view that creates,
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
the compose window, rather than the compose window itself.
Is this atleast possible? Or should we stick to Apple provided blue itself???
Since the MFMailComposeViewController is a subclass of UINavigationController, simply do this:
[[picker navigationBar] setTintColor:[UIColor redColor]];
The iPhone Human Interface Guidelines do not forbid to use custom colors but recommends the standard colors (blue and black).
Yes it is possible.
Just add a objective-c category in the UINavigationBar class overriding the drawInRect Method.
This way you can do want.
The disadvantage, all your navigation bars will change :)
[[picker navigationBar] setTintColor:[UIColor blackColor]];
....makes the Cancel and Send buttons black too. They are not blue and do not change color when pressed.
You can also try this code....
MFMailComposeViewController *mailComposeView = [[MFMailComposeViewController alloc] init];
mailComposeView.navigationBar.tintColor = [UIColor cyanColor];

Change the color of a Tabbar on the iPhone

Our designers want to change the color of the default UITabBar. Of course they do.
They want the background to be green, and the icon highlights to be white, as opposed to the black/blue default color scheme.
Anyone have any experience or suggestions to do this?
You have to subclass the UITabBarController and implement custom drawing.
Check out this SO question. Changing Tint / Background color of UITabBar
Since iOS5 is released, you can now use the property tintColor.
i.e.:
tabBar.tintColor = [UIColor greenColor];
I have try this one and its working for me!!!
[self.TabBarController.tabBar setTintColor:[UIColor colorWithRed:0.1294 green:0.5686 blue:0.8353 alpha:1.0]];
[self.TabBarController.tabBar setTintColor:[UIColor "YOUR COLOR"];
Hope it'll help you also!!!
iOS 5.0 fixes this issue but the solution is under NDA. Look up UITabBar in your documentation for an EASY way to do what you want to do.
Be careful. If your app is going for submission to the app store, Apple may reject it if you're modifying their prescribed color scheme.
Theres a useful link here: http://duivesteyn.net/2010/01/16/iphone-custom-tabbar-background-image/
This can be done with a little private API hacking.