I've implemented a Navigation Controller for my View Controller with storyboard. Now i want changing navigation bar title font and size with Attribute Inspector but it doesn't work and i don't understand why. Title color changes but font dont.
ps: the color changing is visible only at runtime and not in the storyboard.
You need to select navigation Bar and then you can set relevant properties. Please check attached image. It might help you.
When I tried to set the font, my font field was grayed out. But all I needed to do was change type to System and then again to Custom. It worked:-) Now I can choose my custom font
For me Bartłomiej Semańczyk's change to system font & change back trick only works to set the font to a particular system-included font. For custom fonts that I've added, the font face gets set to my custom font but it always gets displayed as size ~16 or so regardless of what size I select in the storyboard.
So the best way I can find to do this is to set self.navigationController.navigationBar.titleTextAttributes in the view controller's viewDidLoad method.
Note that you don't need to do this in every view controller you push onto this navigation stack, just the first one that gets displayed since it sets the property on the navigationBar itself not on the navigationItem. If you're subclassing UINavigationController already, that's the most logical place to set this but I'd rather not subclass it just for this one line change.
Related
I would like to know if there is a way to detect the current font and size used by iOS for the title shown in the navigation bar.
Is it possible to detect what Font (name and size) it's been used by the system?
Yes. You can run through all subviews of the navigation bar and find displayed labels, then you can get the font.
I have set an backgroundImage for my navigationbar. This works fine. But I would like to have the navigationbar height to be adjusted to the background image. At the moment the width of the background images is also not set according to the screen size.
I tried setting the height of the navigationbar like described here. This shows a bigger navigationbar for like a second but then it shrinks to its default size again.
Does anyone know how to achieve what I want? Here is an example of what I want to achieve: image
Apple Documentation:
It is permissible to customize the appearance of the navigation bar
using the methods and properties of the UINavigationBar class but you
must never change its frame, bounds, or alpha values or modify its
view hierarchy directly.
To achieve the effect seen in the image you tagged, they are most likely using a collection view to layout their data and that image is part of the collection view's header. They made the navigation bar background color clear, but the image is definitely not part of the navigation bar itself.
Apple recommends to never change the frame of a navigation bar manually because it messes with the layout code of its subviews and animation methods.
You could either subclass the navigation bar and attempt to create something similar, or go the easier route and make the navigation bar clear (UIColor(white: 0, alpha: 1) not .clear otherwise it might show up incorrectly) and have an underlying view display the image (e.x. a collection view whos header extends to the top of the view controller).
This will allow you to adjust the image height and width freely without subclassing the navigation bar, and creating potential bugs.
You can make custom NavigationBar class.
It can be help you
https://developer.apple.com/library/archive/samplecode/NavBar/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007418-Intro-DontLinkElementID_2
I am a beginner using storyboards for iOS. I have been using the tab bar controller to show my content.
When I first implemented the UITabBar I could see all the icons at the bottom of the UITabController in storyboard and I could see the UITabBarItem at the bottom of each UIViewController. Why is there now a blank grey bar? I can't seem to change the content either in storyboard. I tried adding another UITabBarController but got the same problem, it also has a dark grey bar at the bottom. However when I run the app all the icons appear. How do I fix this so I can see the UITabBarItems in storyboard or should I just try updating them programmatically instead?
Showing a tab bar or not is one of the couple of simulated metrics used in Interface Builder. As such they only serve to have an idea of how your controller would look under different conditions but do not really change anything to the actual controller.
Most of the time the default Inferred option will try to deduce from the Storyboard configuration how it should look like. In your case just connect the tab bar controller to your controller through the viewControllers outlet.
In contrast, below you have some View Controller properties that change both how your controller is previewed in Interface Builder and also its actual behavior (for instance try changing Adjusts Scroll View Insets or Extended Edges).
I don't understand why the background color setting in the storyboard doesn't work for my navigation controller? (See picture)
http://ctrlv.in/299323
I have here set it to bright red but as you can see it does nothing in the storyboard or to the app when I build it.
Any thoughts?
I know I can set the color programmatically, and this is what I am currently doing. However, it would be nice to see the changes in the storyboard so I don't have to build the app every time I make a color change to see the difference.
Yes you can. Notice that you're changing UIView properties not Navigation bar. Look at the screen below:
You have to set Bar Tint property.
I have a project where a custom height navigation bar is used across the app so it is 62px instead 44px tall. I am trying to build and layout my views using the storyboard editor (interface builder) although when using the Top Bar attribute set to Navigation Bar under the simulated metrics under the view controller options, this turns to be the default 44px one and not the custom height navbar (64px) I want.
This way all the view work area shows up on a different size and I always need to calculate what is going to exceed or not.
Is there any way that I can use both simulated metrics and a custom height navbar subclass gracefully while keeping the exact height I will have to work on the remaining space?
It is not possible to change the Simulated Metrics to custom values by Xcode.
A possibility is to design the custom navbar and copy it everywhere instead of the navigation, but then it is not simulated any longer.
Or you could make a little hack by going into
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Xcode/PrivatePlugIns/IDEInterfaceBuilderCocoaTouchIntegration.ideplugin/Contents/Resources
and open CocoaTouchConstraints.plist
In this file you can set the value of NavigationBar to the desired values. So if you want a Navigation Bar that is 60 high just set Maximum and minimum height to 60:
<key>NavigationBar</key>
<dict>
<key>MaximumSize</key>
<string>{10000, 60}</string>
<key>MinimumSize</key>
<string>{0, 60}</string>
</dict>
After saving you need to restart Xcode and you NavigationBar will have the desired height.
I'm afraid you can't really do that, if you want to have a similar behavior and a correct auto layout and constraints directly in Interface Building add a simple view for your custom navbar class with the correct metrics, (it will work just fine as the navigation bar inherits from UIView) just add the view, set the custom class, and add the constraints for both, the navigation bar and the top objects of your view.