IOS UI Tab Development
IOS UI Tab Development (iOS 8)
The tab style is similar to a single choice. It can be called radio-style. This is a mainstream layout-design. It makes the content structure of the APP clear, the Development Division logic clear, the classic one is, the clock, and so on.
Summary:
1. UITabBarController inherits UIViewController, which is a ViewController container
2. UITabBarController has one (readonly) TabBar and one or more tabbaritems.
3. Each Item needs to be associated with a custom UIViewController, which has a viewControllers attribute and stores the ViewController corresponding to each TabBarItem. The element sequence in this array is the display sequence on the Tabbar.
4. Title-Text displayed by TabBarItem. If it is not set by yourself, the default value is the title of the corresponding ViewController. The Image should be set automatically.
5.UITabBarControllerDelegate
Protocol provides the operation callback API for monitoring TabBar
6. Each ViewController of Embed in UITabBarController automatically adjusts its layout to avoid blocking the Bar below.
7. If the number of tabbaritems is greater than or equal to 6, TabBarController is automatically adjusted as follows:
Next let's talk about API
@ Property (nonatomic, readonly) UITabBar * tabBar
Read-only, do not try to modify, In order to configure the item, you should modify the ViewControllers attribute, it has the meaning of only for situations where you want to display an action sheet usingshowFromTabBar:
Method ofUIActionSheet
Class.
Manage ViewControllers APIs
@ Property (nonatomic, copy) NSArray * viewControllers
This obviously supports customization. In addition, when this attribute is assigned,customizableViewControllers
The property value is the same
If this attribute is changed at runtime, if the previously selected index does not exist, the select index = 0 by default.
-(Void) setViewControllers :( NSArray *)viewControllers
Animated :( BOOL)animated
It doesn't make much sense. is self-measurement required?
@ Property (nonatomic, copy) NSArray * customizableViewControllers
This usage is illustrated in the preceding figure.
@ Property (nonatomic, readonly) UINavigationController * moreNavigationController
A NavigationController generated to manage customizableViewControllers
Manage the Selected Tab APIs
@ Property (nonatomic, assign) UIViewController * selectedViewController
You can set or access the currently selected ViewController.
@ Property (nonatomic) NSUInteger selectedIndex
Corresponds to selectedViewController
UITabBarControllerDelegate
Determines which tab should be selected
Execute action after selecting the tab
Execute action before and after the custom tab order
Override view rotation settings
Allows you to configure custom transition animations.
For the corresponding method, see the documentation.
UITabBar
// Allows you to customize the items layout. A view with the Done button is automatically displayed.
[Self. tabBar beginCustomizingItems: @ [item1, item3, item2];
// Set the style of the item position
Self. tabBar. itemPositioning = UITabBarItemPositioningCentered;
// Set the Centered style for the following two attributes. Otherwise, the Centered style is invalid.
Self. tabBar. itemSpacing = 80366f;
Self. tabBar. itemWidth = 30366f;
UITabBarItem
UITabBarItem * item = [[UITabBarItem alloc] initWithTitle: @ "Test" image: nil tag: 0];
// Set the title-text color on the item
[Item setTitleTextAttributes: @ {NSForegroundColorAttributeName: [UIColor redColor]} forState: UIControlStateNormal];
[Item setTitleTextAttributes: @ {NSForegroundColorAttributeName: [UIColor darkGrayColor]} forState: UIControlStateSelected];
// Set the image attribute of the Item, To prevent system coloring. By default, the system uses the alpha value of the image resource To generate an image. In many cases, we set the reason why the image does not work.
Item. image = [[UIImage imageNamed: @ "color"] imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal];
// Set the concave position of the background image. The positive value is reduced inward and the negative value is extended outward.
UIEdgeInsets insets;
Insets. left =-5;
Insets. right =-5;
Item. imageInsets = insets;
// Set the offset of item. title
UIOffset offset;
Offset. horizontal = 30;
Offset. vertical =-10;
[Item setTitlePositionAdjustment: offset];
UITabBarDelegate
Provides the callback API for operating the Tab. For more information, see the official documentation.
Summary:
Content display class: layout-design on the outermost layer of the function class APP. It is recommended to use the Tab-based method.