美文网首页
UITabBarController和UITabBar

UITabBarController和UITabBar

作者: 越来越胖了 | 来源:发表于2019-09-24 20:22 被阅读0次

首先看官方介绍:

UITabBar
You should never attempt to manipulate the UITabBar object itself stored in this property. If you attempt to do so, the tab bar view throws an exception. To configure the items for your tab bar interface, you should instead assign one or more custom view controllers to the viewControllers property. The tab bar collects the needed tab bar items from the view controllers you specify.

The tab bar view provided by this property is only for situations where you want to display an action sheet using the showFromTabBar: method of the UIActionSheet class.
(永远不要试图操作存储在此属性中的UITabBar对象本身。如果尝试这样做,选项卡栏视图将抛出异常。要为选项卡栏接口配置项,应该将一个或多个自定义视图控制器分配给viewControllers属性。选项卡栏从您指定的视图控制器收集所需的选项卡栏项。

此属性提供的选项卡栏视图仅用于希望使用UIActionSheet类的showFromTabBar:方法显示动作表的情况。)

UITabBarController。标签栏控制器,用于构建树标签导航模式;

TabBar 是一个UI控件,UITabBarController通过 viewControllers 添加了多少子视图控制器,那么UITabBar内部就会有多少个UITabBarButton作为子控件与之对应。
例子:

  • tabbarC. viewControllers = @[vc1,vc2,vc3];那么UITabBar中会对于生成三个TabBarButton1,TabBarButton2,TabBarButton3与之一一对应;
  • 且通过vc1.tabBarItem.title=@"首页";vc1.tabBarItem.Image = [UIImage imageWithName:@
    "home_tabbar@2x.png"];可以设置对于的TabBarButton1的属性;
  • UITabBar可以通过UITabBarItem去设置, UITabBarItem有以下属性方法:
- (instancetype)init NS_DESIGNATED_INITIALIZER;
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder NS_DESIGNATED_INITIALIZER;
/* The unselected image is autogenerated from the image argument. The selected image
 is autogenerated from the selectedImage if provided and the image argument otherwise.
 To prevent system coloring, provide images with UIImageRenderingModeAlwaysOriginal (see UIImage.h)
 */
- (instancetype)initWithTitle:(nullable NSString *)title image:(nullable UIImage *)image tag:(NSInteger)tag;
- (instancetype)initWithTitle:(nullable NSString *)title image:(nullable UIImage *)image selectedImage:(nullable UIImage *)selectedImage NS_AVAILABLE_IOS(7_0);
- (instancetype)initWithTabBarSystemItem:(UITabBarSystemItem)systemItem tag:(NSInteger)tag;

@property(nullable, nonatomic,strong) UIImage *selectedImage NS_AVAILABLE_IOS(7_0);

@property(nullable, nonatomic, copy) NSString *badgeValue;    // default is nil
@property (nonatomic, readwrite, copy, nullable) UIColor *badgeColor NS_AVAILABLE_IOS(10_0) UI_APPEARANCE_SELECTOR;

🍒还很多,同时继承父类UIBarItem的属性:🍒
@property(nonatomic,getter=isEnabled) BOOL         enabled;      // default is YES
@property(nullable, nonatomic,copy)             NSString    *title;        // default is nil
@property(nullable, nonatomic,strong)           UIImage     *image;        // default is nil
@property(nullable, nonatomic,strong)           UIImage     *landscapeImagePhone NS_AVAILABLE_IOS(5_0) __TVOS_PROHIBITED; // default is nil

// Higher-resolution version of the standard image. Default is nil. Used for rendering assistive UI (e.g. for users with visual impairments who need large text). If not provided, the system may attempt to generate an image based on the standard image (for instance, by rasterizing matching PDF representations at a higher resolution).
@property(nullable, nonatomic,strong)           UIImage     *largeContentSizeImage API_AVAILABLE(ios(11.0));

@property(nonatomic)                  UIEdgeInsets imageInsets;  // default is UIEdgeInsetsZero
@property(nonatomic)                  UIEdgeInsets landscapeImagePhoneInsets NS_AVAILABLE_IOS(5_0) __TVOS_PROHIBITED;  // default is UIEdgeInsetsZero. These insets apply only when the landscapeImagePhone property is set.
@property(nonatomic)                  UIEdgeInsets largeContentSizeImageInsets API_AVAILABLE(ios(11.0)); // default is UIEdgeInsetsZero. These insets apply only when the largeContentSizeImage property is set.
@property(nonatomic)                  NSInteger    tag;          // default is 0

kvc对readonly的属性的重写,可以修改readonly的属性值😑

相关文章

网友评论

      本文标题:UITabBarController和UITabBar

      本文链接:https://www.haomeiwen.com/subject/soapuctx.html