iOS开发中标签控制器的使用(2)

//风格 分黑白两种
@property(nonatomic) UIBarStyle barStyle;
//是否透明效果
@property(nonatomic,getter=isTranslucent) BOOL translucent;
 
 2、UITabBarDelegate

//选中标签时调用
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item;
//将要开始编辑标签时
- (void)tabBar:(UITabBar *)tabBar willBeginCustomizingItems:(NSArray<UITabBarItem *> *)items;          //已经开始编辑标签时       
- (void)tabBar:(UITabBar *)tabBar didBeginCustomizingItems:(NSArray<UITabBarItem *> *)items;         
//将要进入编辑状态时
- (void)tabBar:(UITabBar *)tabBar willEndCustomizingItems:(NSArray<UITabBarItem *> *)items changed:(BOOL)changed;
//已经进入编辑状态时
- (void)tabBar:(UITabBar *)tabBar didEndCustomizingItems:(NSArray<UITabBarItem *> *)items changed:(BOOL)changed;
 
五、再看UITabBarItem

和NavigationItem类似,标签栏上的item也可以自定义,一些方法如下。

初始化方法:

//通过标题和图案进行创建
- (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;
//创建系统类型的
- (instancetype)initWithTabBarSystemItem:(UITabBarSystemItem)systemItem tag:(NSInteger)tag;
 

UITabBarSystemItem的枚举如下:

typedef NS_ENUM(NSInteger, UITabBarSystemItem) {
    UITabBarSystemItemMore,//更多图标
    UITabBarSystemItemFavorites,//最爱图标
    UITabBarSystemItemFeatured,//特征图标
    UITabBarSystemItemTopRated,//高级图标
    UITabBarSystemItemRecents,//最近图标
    UITabBarSystemItemContacts,//联系人图标
    UITabBarSystemItemHistory,//历史图标
    UITabBarSystemItemBookmarks,//图书图标
    UITabBarSystemItemSearch,//查找图标
    UITabBarSystemItemDownloads,//下载图标
    UITabBarSystemItemMostRecent,//记录图标
    UITabBarSystemItemMostViewed,//全部查看图标
};

UITabBarItem常用属性:

//设置选中图案
@property(nullable, nonatomic,strong) UIImage *selectedImage;

下面这个属性可以设置item的头标文字:

con.tabBarItem.badgeValue = @"1";


 
//设置标题的位置偏移
@property (nonatomic, readwrite, assign) UIOffset titlePositionAdjustment;

由于UITabBarItem是继承于UIBarItem,还有下面这个属性可以设置使用:

//标题
@property(nullable, nonatomic,copy)            NSString    *title; 
//图案   
@property(nullable, nonatomic,strong)          UIImage    *image; 
//横屏时的图案     
@property(nullable, nonatomic,strong)          UIImage    *landscapeImagePhone;
//图案位置偏移
@property(nonatomic)                  UIEdgeInsets imageInsets;
//横屏时的图案位置偏移
@property(nonatomic)                  UIEdgeInsets landscapeImagePhoneInsets ;
//设置和获取标题的字体属性
- (void)setTitleTextAttributes:(nullable NSDictionary<NSString *,id> *)attributes forState:(UIControlState)state;
- (nullable NSDictionary<NSString *,id> *)titleTextAttributesForState:(UIControlState)state;

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/717a31b87f38cb2b917fc05d0520b7eb.html