Changing UIToolbar UIBarMetrics - ios

Is there anyway to have the UIBarMetrics of a custom UIToolbar change when the device is rotated? I would prefer it happen automatically but if there is something I can do during rotation that would also be ok. I would like to use UIAppearance so manually adjusting the height of the bar won't work.

I think you need
UIToolbar *toolbar = [UIToolbar appearance];
[toolbar setBackgroundImage:[UIImage imageNamed:#"toolbarLandscapePhone"] forToolbarPosition:UIToolbarPositionBottom barMetrics:UIBarMetricsLandscapePhone];
You can simple to setBarMetrics to UIBarMetricsLandscapePhone

Related

UIButton appearance setBackgroundColor effecting navigation bar now after update

Xcode or iOS update has made the following code below function differently because now the navigation bar button background has a background color, unlike previously. Any fix? I want all buttons to have the same global color, but now it effects the navigation bar buttons which I dont want. I would like it transparent like before.
[[UIButton appearance] setBackgroundColor:[Helper getColor:self.application.color]];
As this particular UIButton is inside a UINavigationBar you could try applying a second specific appearance to 'override' the first general appearance set.
For example calling specifically,
[[UIButton appearanceWhenContainedIn:[UINavigationBar class], nil]
setBackgroundColor:[UIColor clearColor] forState:state barMetrics:metrics];
after you call,
[[UIButton appearance] setBackgroundColor:[Helper getColor:self.application.color]];
To override the general with the specific.
Docs Link: https://developer.apple.com/documentation/uikit/uiappearance

Setting the tint color when using form sheet modal presentation does not work on iPad

I have a UISearchBar in a modal UIViewController that has presentationStyle set to UIModalPresentationStyleFormSheet.
Setting the tint colour on the search bar is only obeyed on the iphone. The iPad still ends up using the app tint color. Any reason why this is happening?
_searchBar = [[UISearchBar alloc] init];
_searchBar.tintColor = [UIColor whiteColor];
why dont you try appearance for search bar in applicationlaunch.
[[UISearchBar appearance] setTintColor:[UIColor whiteColor]];
That didn't work for me. What worked was setting the UITextField appearance, but that's iOS7 only. You can also loop over the bar's subviews and change the UITextField's tintColor:
[[UITextField appearance] setTintColor:[UIColor blackColor]];

How to make a custom UIView to combine with UINavigationBar make it looks as one

As you can see below, the three buttons: STORE,AREA and All. These buttons looks like the UINavigationBar and them are combined together. I tried in storyboard, I added a custom UIView and try to set it's colour match the UINavigationBar background color. But it always has differences, and I can see the border line between UINavigationBar and the custom UIView. How to make a UIView to combine with the UINavigationBar to make it all looks like they are combined.
iOS 7 has shadow next to the navigation bar. Try below to remove that shadow:
if (IS_IOS7) {
[[UINavigationBar appearance]setShadowImage:[[UIImage alloc] init]];
}
You can change the navigation and status bar background only in iOS7. For this, you can use
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"nav_bg.png"] forBarMetrics:UIBarMetricsDefault];
The size of the nav_bg.png should be 320*64 px
If you want to simply change the color of navigation bar you can use
[[UINavigationBar appearance] setBarTintColor:[UIColor blueColor]];

How do you set the background color of a UINavigationbar programatically?

I am using a cocoa iOS component from cocoacontrols.com, which is NOT using storyboards. This class creates a new modal view and the modal view has a NavigationBar at the top. I am trying to get the color of the navigationBar to change. In all my other views, which are storyboard based, I use a base class of STBaseViewController which sets the navigationBar as white.
I have changed this cocoacontrol class to be a STBaseViewController instead of a UIViewController, but it still is not changing my background to white.
#interface BZPasscodeFieldController : STBaseViewController
In the BZPasscodeFieldController, which they don't make any reference to a navigationbar, so I am not sure how its even showing up (again it has no storyboard's only xibs and they don't have navigationbars)?
Anyway, does anyone know how to make the navigationbar background color white programatically?
Further, in all my storyboard viewControllers that have a UINavigationBar, I have added a UIButton over the area where the title goes, so that I can easily change the font/style and also make it clickable. I need to add this same UIButton to the uinavigationBar of this BZPasscodeFieldController created programatically. How would I go about doing that?
To Set Navigationbar Background Color:
[[UINavigationBar appearance] setBarTintColor:[UIColor orangeColor]];
To set Navigationbar Tint Color:
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
For your question about the button on the place of title of navigationBar. Each navigationBar has a titleView property, you can assign any view to it. For example take a look at this method, you can call it in your BZPasscodeFieldController:
- (void) setNavigationBarTitleButton
{
UIButton* centralButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 44)];
[centralButton setImage:navigationCentralButtonImage forState:UIControlStateNormal];
[centralButton setShowsTouchWhenHighlighted:TRUE];
[centralButton addTarget:self action:#selector(goHigher) forControlEvents:UIControlEventTouchDown];
self.navigationItem.titleView = centralButton;
}
For your previous question the answers provided already are all correct, calling them in the right place(for example in AppDelegate's application:didFinishLaunchingWithOptions: should make it work well, unless something is messed up in your custom view controller classes.
[[UINavigationBar appearance] setTintColor:[UIColor blueColor]];
[self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];

Adding UIToolbar programmatically

What am I doing wrong here ? I just don't see the toolbar at the bottom of screen Here's my code.
CGRect rect = self.view.frame;
UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(rect.origin.x,
rect.size.height-44,
rect.size.width,
44)];
self.bottomToolbar = toolBar;
[toolBar release];
[_bottomToolbar setBackgroundImage:nil
forToolbarPosition:UIToolbarPositionBottom
barMetrics:UIBarMetricsDefault];
[self.view addSubview:_bottomToolbar];
You need to set the toolbar's autosizingMask to the "flexible top margin" value.
Also, your code deals with the toolBar variable, the bottomToolbar property, and the _bottomToolbar ivar. Either use the property or the ivar. It's confusing to use both like you are.
there is missing one line, its sizeToFit or makeKeyAndVisible()
Just look in the example in the ViewControllerProgrammingGuide

Resources