I'm in the process of incorporating iOS 5's UIAppearance feature to give my universal app a unique theme. Currently, I have implemented some code in my App Delegate to give the app custom navigation bars:
UIImage *navBarImage = [[UIImage imageNamed:#"navigationBar.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(7, 7, 7, 7)];
[[UINavigationBar appearance] setBackgroundImage:navBarImage forBarMetrics:UIBarMetricsDefault];
This works well and changes all the navigation bars from Apple's plain style to a bright gradient. However, the problem I am having is that it is overriding some style that I don't want it too. My particular issue is that it overrides the navigation bar background in the iPad's UIPopoverController, creating an ugly user experience. Please tell me how to fix it.
Edit: Please note that this is an universal app and I open the image picker through a UIPopoverController on the iPad and a modal view on the iPhone/iPod. I only want to remove the custom background for the navBar on the iPad popover, not on the modal view.
How it currently looks like:
How I want it to look like:
Thanks in advance for your help,
Guvvy
Try using the +appearanceWhenContainedIn: method to remove your background-image customization from navigation bars when they’re contained in popover controllers. Something like this:
[[UINavigationBar appearanceWhenContainedIn:[UIPopoverController class], nil] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
It’s not clear from the documentation whether setting a navigation bar’s background image to nil restores its default appearance—if that doesn’t work, you might have to take the opposite approach, and provide the list of non-popover container view controllers you’re using to +appearanceWhenContainedIn:.
Related
In my app I have a TabbarController. One of the tabs opens a View which starts the iPhone camera. This CameraView is part of a SDK which is developed by another company. So I can't modify the class of this CameraView.
My problem is that I have to implement a UINavigationBar in this CameraView. I've solved this through a annotationView (this navigationbar is not handled by a navigationcontroller):
[self.annotationView addSubview:navbar];
All works well except the autoresizing matter. If I turn the phone to landscape mode the navigationbar is too short.
I have already tried to set Autoresizingmask but that doesn't help.
Do you have any ideas how I can force the navigationbar to autoresize?
Thanks in advance
Try to adjust the frame of the navigationbar manually, instead of using autorotation.
-willRotateFromInterfaceOrientation:(UIInterfaceOrientation)fio toInterfaceOrientation:(UIInterfaceOrientation)tio
{
if(tio == UIInterfaceOrientationLandscape)
//set navbar frame
else
//...
}
I have an UITabBar in my application. One of the tab bar icons looks like a loading symbol. When the user presses the loading button I want the icon to spin/rotate until the loading is done. Should I use UIImageView to animate or something else? How should I make this happen?
Jacos, unfortunately you cannot do that with the UITabBarController and manipulate the tabBarController's tabBar properties. My best bet would be that you use a UIToolBar and assign a black color and make it appear like a tabBar and have buttons added in them as a subView so that they look like tabBarItems.
Its much more customizable, and you can even provide a scrolling experience and add more buttons to it.
I know this question is 4 years old but I had the same problem and managed to fix it by reading the tutorial in here:
https://medium.com/#werry_paxman/bring-your-uitabbar-to-life-animating-uitabbaritem-images-with-swift-and-coregraphics-d3be75eb8d4d#.bjfpbdnut
The main point is to get the view for desired UITabBarItem and the get the UIImageView from it in viewDidLoad:
UIView *plusView = self.tabBar.subviews[1];
self.plusImageView = plusView.subviews.firstObject;
self.plusImageView.contentMode = UIViewContentModeCenter;
Then in didSelectItem method you can do this:
[UIView animateWithDuration:0.4 animations:^{
[self.plusImageView setTransform:CGAffineTransformMakeRotation(M_PI/4)];
}];
My code only rotate the image view for 45 degrees but you can change as you wish.
I guess you could change the UITabBarItem's icon on a timer, but that seems pretty kludgey. You would have to pre-render each frame of your "loading" icon rather than rotate an ImageView.
Another hackey solution would be to add your ImageView to the UIWindow and move it on top of the TabBarController's TabBar (adding it to the TabBar itself is asking for trouble).
You shouldn't try to animate the actual UIImageView within the UITabBarController. I would take this approach:
Set the image for the relevant tab to nil or a blank image.
Create a UIActivityIndicatorView and add it over the tab bar. Position it over the correct tab.
[self.tabBarController.tabBar addSubview:activityIndicatorView];
When your loading task has completed, restore the normal image to the tab and remove the activityIndicator from the tab bar.
The app I'm working on has a custom nab bar but supports iOS 4.2-iOS 5, so I need to set the UINavigationBar background and tint in this old school way in my app delegate.
#implementation UINavigationBar (UINavigationBarCategory)
- (void)drawRect:(CGRect)rect {
self.tintColor = [UIColor colorWithRed:42.0/255.0
green:164.0/255.0
blue:182.0/255.0
alpha:1.0];
UIImage *img = [UIImage imageNamed:#"navbar_bg.png"];
[img drawInRect:CGRectMake(0.0, 0.0,
self.frame.size.width,
self.frame.size.height)];
}
#end
This works for the most part, but I noticed when the app is first starting, the UIBarButtonItems flash the default navigation bar color for a second before they correct themselves and change color to match the navigation bar. Interestingly, the navigation bar itself uses the background image correctly from the get-go.
To be clear, I'm using setBackgroundImage for UINavigationBar on iOS 5 devices which works as expected so the flash is only in iOS 4.
Anyone have any insight on why this would happen and/or how to fix it?
The bar button items are the wrong color? You can manually set their tint color in viewDidLoad: to the tint color
navigationBar.rightBarButtonItem.tintColor = [UIColor ...]
if you're using a nib file. Otherwise you can do the same thing in loadView: . Either way this code will get executed as part of the initial draw loop so you'll have the proper color without any flashing.
Also for future reference, it's technically incorrect to override a method inside a category. (The latest version of Xcode, 4.3, will give you a warning about this). You should either properly subclass UINavigationBar or do "method swizzling". But that's pretty tough so don't worry about it right now :)
If you call the class with the code referenced in viewDidLoad try moving it to awakeFromNib
I want to change the picker view bakground color. I try this way but not worked.
doublePicker.backgroundColor = [self RGBColorR:85 G:17 B:92];
- (UIColor *)RGBColorR:(double)red G:(double)green B:(double)blue {
return [UIColor colorWithRed:(red/255.00) green:(green/255.00) blue:(blue/255.00) alpha:1.00];
}
I want to do picker view like in picture. How can I do this? Thanks for your reply.
you can add subviews over certain areas of your pickerview..
use:
[picker addSubview: coverView]; //adding subviews to different area of the picker
you're going to find yourself playing with alot of CGRect to get thing to fit properly. If you want to change the entire thing you're going to have to override some methods that handle the touch events etc..
this tutorial might help you create a custom picker
https://developer.apple.com/iphone/library/samplecode/UICatalog/
You cannot change the appearance of UIPickerView, even the size, it's the most unchangeable UI element in iOS. Best you can do is build custom by yourself, using UIScrollView with paging enabled.
I'm trying to make my app feel more customized with a shaded navigation bar. For all controllers that I create, I can change the color of the navbar using:
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
So all of my controllers use black navigation bars. However, when such controller is viewed in the "...More" tabbar section, the tint reverts to blue.
How do I change the ...More navigation controller tint?
As a side note, how do I would I go about globally define the style that my app is using?
edit:
To save some work, I defined a custom MyColors class, and put these methods in it:
+(UIColor*)navBarColor;
+(UIColor*)toolBarColor;
+(UIColor*)lightFontColor;
+(UIColor*)darkFontColor;
+(UIColor*)transparentColor;
This will help me change the colors of a UITabBar in the future without having to go hunting through each UIViewController and changing the color by hand!
Thank you!
If you want to set a global color then use the new appearance proxy.
for example,
[[UINavigationBar appearance] setTintColor:myColor];
Any UIKit object that adopts the UIAppearence protocol can be set globally like this.
self.moreNavigationController.navigationBar.tintColor = [UIColor blackColor];