iOS开发UITabbarController常用属性方法

//

//  AppDelegate.m

//  UITabBarController+UINavigationController

#import "AppDelegate.h"

 

@interface AppDelegate ()

 

@end

 

@implementation AppDelegate

 

 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    

    //1.创建Window

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    self.window.backgroundColor = [UIColor whiteColor];

    

    //a.初始化一个tabBar控制器

    UITabBarController *tb=[[UITabBarController alloc]init];

    //设置控制器为Window的根控制器

    self.window.rootViewController=tb;

    

    /*

     UITabBarSystemItem的多种设置:

     UITabBarSystemItemMore,//更多图标

     UITabBarSystemItemFavorites,//最爱图标

     UITabBarSystemItemFeatured,//特征图标

     UITabBarSystemItemTopRated,//高级图标

     UITabBarSystemItemRecents,//最近图标

     UITabBarSystemItemContacts,//联系人图标

     UITabBarSystemItemHistory,//历史图标

     UITabBarSystemItemBookmarks,//图书图标

     UITabBarSystemItemSearch,//查找图标

     UITabBarSystemItemDownloads,//下载图标

     UITabBarSystemItemMostRecent,//记录图标

     UITabBarSystemItemMostViewed,//全部查看图标

     */

    

    //b.创建子控制器

    UIViewController *c1=[[UIViewController alloc]init];

    c1.view.backgroundColor=[UIColor grayColor];

    c1.view.backgroundColor=[UIColor greenColor];

    c1.tabBarItem.title=@"消息";//标题文字

    //设置标题的位置偏移

    //@property (nonatomic, readwrite, assign) UIOffset titlePositionAdjustment;

    c1.tabBarItem.image=[UIImage imageNamed:@"1"];//图标

    //landscapeImagePhone 横屏是的图标

    //imageInsets  图标位置的偏移

    //landscapeImagePhoneInsets  横屏时图标的偏移

    

    /*

    设置和获取标题的字体属性

    - (void)setTitleTextAttributes:(nullable NSDictionary<NSString *,id> *)attributes forState:(UIControlState)state;

    - (nullable NSDictionary<NSString *,id> *)titleTextAttributesForState:(UIControlState)state;

     */

    c1.tabBarItem.selectedImage = [UIImage imageNamed:@"11"];//选中时的图标

    c1.tabBarItem.badgeValue=@"123";//提醒数字

    

    UIViewController *c2=[[UIViewController alloc]init];

    c2.view.backgroundColor=[UIColor brownColor];

    c2.tabBarItem.title=@"联系人";

    c2.tabBarItem.image=[UIImage imageNamed:@"2"];

    

    UIViewController *c3=[[UIViewController alloc]init];

    c3.view.backgroundColor = [UIColor orangeColor];

    c3.tabBarItem.title=@"动态";

    c3.tabBarItem.image=[UIImage imageNamed:@"3"];

    

    UIViewController *c4=[[UIViewController alloc]init];

    c4.view.backgroundColor = [UIColor grayColor];

    c4.tabBarItem.title=@"设置";

    c4.tabBarItem.image=[UIImage imageNamed:@"4"];

    

    

    //c.添加子控制器到ITabBarController中

    //c.1第一种方式

    //    [tb addChildViewController:c1];

    //    [tb addChildViewController:c2];

    

    //c.2第二种方式

    tb.viewControllers=@[c1,c2,c3,c4];

    

    

    //2.设置Window为主窗口并显示出来

    [self.window makeKeyAndVisible];

    

    

    

    

    // Override point for customization after application launch.

    return YES;

}

#pragma mark 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;

 

 

 delegate

 //选中标签时调用

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

 

 */

 

 

- (void)applicationWillResignActive:(UIApplication *)application {

    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.

}

 

 

- (void)applicationDidEnterBackground:(UIApplication *)application {

    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.

    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

}

 

 

- (void)applicationWillEnterForeground:(UIApplication *)application {

    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.

}

 

 

- (void)applicationDidBecomeActive:(UIApplication *)application {

    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

}

 

 

- (void)applicationWillTerminate:(UIApplication *)application {

    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

}

 

 

@end

 

posted @ 2017-08-28 14:08  屋巢  阅读(1330)  评论(0编辑  收藏  举报