iOS开发中标签控制器的使用——UITabBarController(二)

简介: iOS开发中标签控制器的使用——UITabBarController

四、关于标签栏TabBar


       通过自定义标签栏的一些属性,使我们可以更加灵活的使用tabBar。


1、UITabBar属性和方法


设置标签:


@property(nullable,nonatomic,copy) NSArray<UITabBarItem *> *items;  

//设置选中的标签    

@property(nullable,nonatomic,assign) UITabBarItem *selectedItem;

- (void)setItems:(nullable NSArray<UITabBarItem *> *)items animated:(BOOL)animated;

设置自定义标签顺序:


//调用这个方法会弹出一个类似上面第二张截图的控制器,我们可以交换标签的布局顺序

- (void)beginCustomizingItems:(NSArray<UITabBarItem *> *)items;  

//完成标签布局

- (BOOL)endCustomizingAnimated:(BOOL)animated;  

//是否正在自定义标签布局

- (BOOL)isCustomizing;

设置tabBar颜色相关:


//设置渲染颜色,会影响选中字体和图案的渲染

@property(null_resettable, nonatomic,strong) UIColor *tintColor;

//设置导航栏的颜色

@property(nullable, nonatomic,strong) UIColor *barTintColor;

设置背景图案:


//设置导航栏背景图案

@property(nullable, nonatomic,strong) UIImage *backgroundImage;

//设置选中一个标签时,标签背后的选中提示图案 这个会出现在设置的item图案的后面

@property(nullable, nonatomic,strong) UIImage *selectionIndicatorImage;

//设置阴影的背景图案

@property(nullable, nonatomic,strong) UIImage *shadowImage

TabBar中标签的宏观属性:


//设置标签item的位置模式

@property(nonatomic) UITabBarItemPositioning itemPositioning;

//枚举如下

typedef NS_ENUM(NSInteger, UITabBarItemPositioning) {

   UITabBarItemPositioningAutomatic,//自动

   UITabBarItemPositioningFill,//充满

   UITabBarItemPositioningCentered,//中心

} NS_ENUM_AVAILABLE_IOS(7_0);

//设置item宽度

@property(nonatomic) CGFloat itemWidth;

//设置item间距

@property(nonatomic) CGFloat itemSpacing;

与导航栏类似,也可以设置tabBar的风格和透明效果:


//风格 分黑白两种

@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;

目录
相关文章
|
6月前
|
iOS开发
Cisco Catalyst 9800 Wireless Controller, IOS XE Release 17.17.1 ED - 思科无线控制器系统软件
Cisco Catalyst 9800 Wireless Controller, IOS XE Release 17.17.1 ED - 思科无线控制器系统软件
193 9
Cisco Catalyst 9800 Wireless Controller, IOS XE Release 17.17.1 ED - 思科无线控制器系统软件
|
10月前
|
iOS开发 开发者
uniapp开发ios打包Error code = -5000 Error message: Error: certificate file(p12) import failed!报错问题如何解决
uniapp开发ios打包Error code = -5000 Error message: Error: certificate file(p12) import failed!报错问题如何解决
593 67
uniapp开发ios打包Error code = -5000 Error message: Error: certificate file(p12) import failed!报错问题如何解决
|
9月前
|
JavaScript 搜索推荐 Android开发
【01】仿站技术之python技术,看完学会再也不用去购买收费工具了-用python扒一个app下载落地页-包括安卓android下载(简单)-ios苹果plist下载(稍微麻烦一丢丢)-客户的麻将软件需要下载落地页并且要做搜索引擎推广-本文用python语言快速开发爬取落地页下载-优雅草卓伊凡
【01】仿站技术之python技术,看完学会再也不用去购买收费工具了-用python扒一个app下载落地页-包括安卓android下载(简单)-ios苹果plist下载(稍微麻烦一丢丢)-客户的麻将软件需要下载落地页并且要做搜索引擎推广-本文用python语言快速开发爬取落地页下载-优雅草卓伊凡
346 8
【01】仿站技术之python技术,看完学会再也不用去购买收费工具了-用python扒一个app下载落地页-包括安卓android下载(简单)-ios苹果plist下载(稍微麻烦一丢丢)-客户的麻将软件需要下载落地页并且要做搜索引擎推广-本文用python语言快速开发爬取落地页下载-优雅草卓伊凡
|
11月前
|
iOS开发 开发者 MacOS
深入探索iOS开发中的SwiftUI框架
【10月更文挑战第21天】 本文将带领读者深入了解Apple最新推出的SwiftUI框架,这一革命性的用户界面构建工具为iOS开发者提供了一种声明式、高效且直观的方式来创建复杂的用户界面。通过分析SwiftUI的核心概念、主要特性以及在实际项目中的应用示例,我们将展示如何利用SwiftUI简化UI代码,提高开发效率,并保持应用程序的高性能和响应性。无论你是iOS开发的新手还是有经验的开发者,本文都将为你提供宝贵的见解和实用的指导。
317 66
|
9月前
|
人工智能 程序员 API
iOS|记一名 iOS 开发新手的前两次 App 审核经历
啥,这玩意也有新手保护期?
218 0
|
11月前
|
存储 监控 API
app开发之安卓Android+苹果ios打包所有权限对应解释列表【长期更新】-以及默认打包自动添加权限列表和简化后的基本打包权限列表以uniapp为例-优雅草央千澈
app开发之安卓Android+苹果ios打包所有权限对应解释列表【长期更新】-以及默认打包自动添加权限列表和简化后的基本打包权限列表以uniapp为例-优雅草央千澈
1028 11
|
11月前
|
开发框架 Android开发 iOS开发
安卓与iOS开发中的跨平台策略:一次编码,多平台部署
在移动应用开发的广阔天地中,安卓和iOS两大阵营各占一方。随着技术的发展,跨平台开发框架应运而生,它们承诺着“一次编码,到处运行”的便捷。本文将深入探讨跨平台开发的现状、挑战以及未来趋势,同时通过代码示例揭示跨平台工具的实际运用。
332 3
|
iOS开发
iOS开发中标签控制器的使用——UITabBarController(一)
iOS开发中标签控制器的使用——UITabBarController
302 0
iOS开发中标签控制器的使用——UITabBarController(一)
|
12月前
|
开发框架 前端开发 Android开发
安卓与iOS开发中的跨平台策略
在移动应用开发的战场上,安卓和iOS两大阵营各据一方。随着技术的演进,跨平台开发框架成为开发者的新宠,旨在实现一次编码、多平台部署的梦想。本文将探讨跨平台开发的优势与挑战,并分享实用的开发技巧,帮助开发者在安卓和iOS的世界中游刃有余。
|
11月前
|
Java 调度 Android开发
安卓与iOS开发中的线程管理差异解析
在移动应用开发的广阔天地中,安卓和iOS两大平台各自拥有独特的魅力。如同东西方文化的差异,它们在处理多线程任务时也展现出不同的哲学。本文将带你穿梭于这两个平台之间,比较它们在线程管理上的核心理念、实现方式及性能考量,助你成为跨平台的编程高手。