I have a category to display a custom image in an app's UINavigationBar. When the app comes back from the background the image sometimes disappears and all I am left with is a white navigation bar with buttons.
The category I'm using is below, can anyone advise please?
#implementation UINavigationBar (CustomImage)
-(void)drawRect:(CGRect)rect {
cardSmartAppDelegate *delegate = (cardSmartAppDelegate *)[[UIApplication sharedApplication] delegate];
[delegate.navImage drawInRect:rect];
}
#end
You shouldn't use a category to override a method. Sometimes it works, but often it doesn't. Rumor has it that it will quit working altogether soon.
See my code in this item for how to do what you want:
Custom UINavigationBar Background
Related
I have a program where I'm working with user authentication and alert views. the problem is quite strange. Every other time I launch the application, the first view appears as normal, and then black, and then back to normal, and so on and so forth.
Launched once:
Launched twice:
Here's the storyboard:
Functionally, it's both the same, but I have no idea what could be causing this problem!
Addition:
The alert is called on viewdidappear.
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self presentAlertViewForPassword];
}
Addition 2 (build settings) (simulator is iphone 4):
Where do you have the AlertView show method? I think this could be because when you press the home button while you are at the UITableViewController and then you launch the app. This is where it starts from.
Do you have the login AlertView code in your applicationDidFinishLaunch?
This black screen seems your alert's view screen. You can set its background image. Do one thing
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
UIImageView *iV = [[UIImageView alloc] initWithFrame:self.view.bounds];
iV.image = [UIImage imageWithNamed:#"imageNameHere"];
[self.view addSubView:iV];
[self presentAlertViewForPassword];
}
Set that Christmas Keeper image on view's background. Hope it helps. Also check your splash screen's image. Search default.png in search box of xcode may be this is different or may be there is two default.png. Just a guess :)
Edit after notice your comment: the launch image is basically a uiimageview on the first page with an image in my directory
So I think that black screen is your launch image because it appears before appearing the first view of your app. You didn't set it yet. Please include a default.png image into your project and it should be same as your first View's `imageView' image.
I have created a project which consist of a tabbarcontroller and a navigationcontroller.
The first view or the first tab is a tableview controller. Now i need to add a splashscreen to my application, so when the app loads it will show a welcome screen and then land on the tableviewcontroller.
My workings so far;
This is added in my viewDidLoad method.
myImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"splash.jpg"]];
myImageView.frame = [[self view] frame];
[self.view addSubview:myImageView];
[self.view bringSubviewToFront:self.myImageView];
The problem is that the splash screen or the UIImageView loads inside the tabbarController/NavigationController, and it does not take the full width and length of the screen. What should i do to fix this programatically ?
In application bundle you need to copy the splash screen images with the name "Default.png" and "Default#2x.png" for Retina. The app will load this automatically, you don't need to do more work.
Here you have a link for this: http://iosdevelopertips.com/cocoa/defaultpng-the-secret-of-the-load-screen.html
Add the images that you want to use to the resources of your project and name them Default.png and Default#2x.png (if you are providing it for a retina screen). Be sure no name them exactly. If you get the capitalisation wrong, it will work in the Simulator (which is not case-sensitive), but not on the device (which is case-sensitive).
Be aware that a "splash screen" is discouraged by the Apple Human Interface Guidelines:
Have you given the Launch Images a look in your target settings?
You would probably want to add the splash screen in the app delegate's didFinishLaunchingWithOptions method. Then start an animation of fade out (or whatever animation you need). Finally removing the splash screen view when the animation is complete.
You have to add the UIImageView to the root's view:
UIView *rootView = [[[[UIApplication sharedApplication] delegate] viewController] view];
[myImageView setFrame:rootView.bounds];
[rootView addSubview:myImageView];
you can use the uiimage view to add an array of images to play an animation, try the following
code in
-(void)viewDidAppear:(BOOL)animated {
animationSplashImageView.animationImages = imageArray;
animationSplashImageView.animationDuration = 5;
animationSplashImageView.animationRepeatCount = 1;
[animationSplashImageView startAnimating];
}
IBOutlet UIImageView* animationSplashImageView;
was defined in the main view of your app.
also you could test your splash using tool Splashx Free, which is on Apple App Store: http://itunes.apple.com/cn/app/splashx-free/id500137095?mt=8
I'm creating an app, that is in some point turning photo library on. The problem is that status bar is black transparent in photo library while i want a default application one (solid white). Is there any way to change it..?
I would add, that i tried regarding to this: iOS SDK - How to get the status bar back when using UIImagePickerController? method:
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[[UIApplication sharedApplication] setStatusBarHidden:NO];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:YES];
}
works only for camera for me, not photo library. Of course i tried with default style too.
UPDATE: i found out a way to change navigation bar:
- (void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController
animated:(BOOL)animated {
navigationController.navigationBar.barStyle = UIBarStyleDefault;
}
This one works, however status bar style is still dark, while i need the default application one, so white.
Many thanks in advance!
Fixed my problem in a different way. To keep the status bar always the same i just added viewDidAppear method, that is written in my main post to my rootViewController, so it is same all the time including turning photo library on
I want a photo viewer in my iphone app and I liked the Three20 photo viewer. I found it somehow hard to integrate it in my own app where I have my typical UINavigationViewController. So far I succeeded in doing the following:
TTURLMap *map = [[[TTURLMap alloc] init] autorelease];
[map from:#"tt://appPhotos" toSharedViewController:[PhotoViewController class]];
[self.navigationController pushViewController:[map objectForURL:#"tt://appPhotos"] animated:YES];
The only problem is that wenn I click back to my original view, its navigation bar keeps the style of the photo viewer (transperant and shows the view under it).
How can I get back my original navigation bar?
My experience: I once used three20's PhotoViewer and every time I went back from the PhotoViewer to my other view. The system status bar remained black and transparent (while it should be with default style). I solved it by manually and programmatically changing the status bar style every time when the back action was triggered.
Yes, this is a bit of an issue for sure. A good solution, as #diwup says, is to implement a manual fix. I tend to subclass TTPhotoViewer when I need it. Not only does it help with this problem but it also makes it much easier to use I find.
If you decide to subclass, then you should use whatever variation of the following you require:
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
self.navigationController.navigationBar.tintColor = myTintColor;
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
}
However, if you don't want to subclass, you can always put the code into the - [viewWillAppear:] method of any class that comes after the photo viewer.
I have a Universal App in which I customize my UINavigationBar.
In my iPhone AppDelegate I use this to achieve it:
#implementation UINavigationBar (CustomImage)
static NSMutableDictionary *navigationBarImages = NULL;
- (void)initImageDictionary
{
if(navigationBarImages==NULL){
navigationBarImages=[[NSMutableDictionary alloc] init];
}
}
- (void)drawRect:(CGRect)rect
{
NSLog(#"drawing navbar2");
UIImage *imageName=[navigationBarImages objectForKey:[NSValue valueWithNonretainedObject: self]];
if (imageName==nil) {
imageName=[UIImage imageNamed:#"bg_titleBar.png"];
UIImage *image = imageName;
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
}
- (void)setMyImage:(UIImage*)image
{
[navigationBarImages setObject:image forKey:[NSValue valueWithNonretainedObject: self]];
[self setNeedsDisplay];
}
#end
Now my questions: why does this code get called, although I start the iPad simulator?
And more important it seems to corrupt the UIPopoverController because it looks like this:
http://awesome-apps.com/pic/ok.png
While it should look somehow like this:
http://awesome-apps.com/pic/nok.png
Besides it corrupts more in my App, but this should be it for starters :)
Can anyone help me with this? Have you ever had a similar experience?
So ignore the fact that it gets called when you run in the iPad simulator, because as you'll see in a minute even if you used two different categories (one for iPhone, one for iPad) you'd still have this problem.
Here's why:
You are using a category to override the UINavigationBar behaviour. I assume you know what that means - crucially any and all navigation bars in your app will use your supplied methods in the category.
This can cause problems if you're using standard apple elements that use UINavigationBars - the exact thing you're seeing in the popover controller. What's happening is the UIPopoverController uses a UINavigationBar. But because you've defined a category, the app assumes you want the popover navbar to use that category as well.
So that's why you're seeing your weird behaviour in your pop-over controller.
As long as you use categories you'll have this problem, because you can't selectively tell the system which bars should use your category.
I'd suggest you tell us exactly you're trying to customise in the navbar, because there are other ways to achieve customisation outside of categories.