关于UITabBarController (非自定义)
2015-08-20 00:49
573 查看
本文所提到的UITabBarController 不是自定义,是系统自带的那种。 具体实现方式如下
新建3个ViewController 如 下图然后 在AppDelegate.h 中
#import <UIKit/UIKit.h> #import "ViewController.h" @interface AppDelegate : UIResponder <UIApplicationDelegate>{ UITabBarController *tabBarController; } @property (strong, nonatomic) UIWindow *window; @property (strong, nonatomic) ViewController *rootView; @end
在 AppDelegate.m 中
#import "AppDelegate.h" #import "FirstViewController.h" #import "SecondViewController.h" #import "ThirdViewController.h" #import "LandingView.h" #import "Masonry.h" @interface AppDelegate () @property (nonatomic,strong)LandingView *landingView; @end @implementation AppDelegate @synthesize rootView; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]bounds]]; self.window.backgroundColor = [UIColor whiteColor]; self.rootView = [[ViewController alloc]init]; [self.window setRootViewController:self.rootView]; [self.window makeKeyAndVisible]; tabBarController = [[UITabBarController alloc]init]; [self.window setRootViewController:tabBarController]; FirstViewController *first = [[FirstViewController alloc]init]; SecondViewController *second = [[SecondViewController alloc]init]; ThirdViewController *third = [[ThirdViewController alloc]init]; tabBarController.viewControllers = [NSArray arrayWithObjects:first,second,third,nil]; UIImage * image1 = [UIImage imageNamed:@"sad.png"]; UIImage * image2 = [UIImage imageNamed:@"bigsmile.png"]; UIImage * image3 = [UIImage imageNamed:@"tongue.png"]; UIImage * image4 = [UIImage imageNamed:@"smirk.png"]; UIImage * image5 = [UIImage imageNamed:@"blah.png"]; UIImage * image6 = [UIImage imageNamed:@"scream.png"]; UITabBar *tabBar = tabBarController.tabBar; UITabBarItem *firstItem = [[tabBar.items objectAtIndex:0]initWithTitle:@"发微博" image:image1 selectedImage:image2]; UITabBarItem *secondItem = [[tabBar.items objectAtIndex:1]initWithTitle:@"信息" image:image3 selectedImage:image4]; UITabBarItem *thirdItem = [[tabBar.items objectAtIndex:2]initWithTitle:@"个人" image:image5 selectedImage:image6]; tabBar.backgroundColor = [UIColor grayColor]; tabBar.barStyle = UIBarStyleBlack; tabBar.selectedImageTintColor = [UIColor colorWithRed:128.0f green:0.0f blue:150.0f alpha:1.0f]; _landingView = [[LandingView alloc]init]; [self.window addSubview:_landingView]; [_landingView mas_makeConstraints:^(MASConstraintMaker *make){ make.top.equalTo(self.window.mas_top); make.left.equalTo(self.window.mas_left); make.right.equalTo(self.window.mas_right); make.bottom.equalTo(self.window.mas_bottom); }]; [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(callback) name:@"cancelView" object:nil]; return YES; } -(void)callback{ _landingView.hidden = YES; }
其中 tabBar.barStyle 是可以改的样式, 系统本身的UITabBarController 不能改变 高度, 还文字和图片的相对位置, 如果要改,还是需要自定义。
相关文章推荐
- UIView 方法列表
- uva 10405 Longest Common Subsequence
- UIautomator输入中文
- Android自动化测试(UiAutomator)简要介绍
- 百度ueditor编辑器代码高亮
- 百度ueditor编辑器代码高亮
- 百度ueditor编辑器代码高亮
- hdu 5400 Arithmetic Sequence
- UITableViewCellEditStyle多功能的实现
- 使用Thread+Handler实现非UI线程更新UI界面
- hdu 5400 Arithmetic Sequence(计数)
- 【JPA】query新对象 需要 构造函数
- IOS-- UIView中的坐标转换
- 独立日记 2015年8月19日 quick 3.5 + sublime环境搭建
- UESTC 94 Bracket Sequence (线段树 区间修改)
- UICollectionView
- Longest Increasing Common Subsequence (LICS)
- POJ - 1679 The Unique MST(次小生成树)
- NSString/NSMutableString/NSNumber/NSValue
- hdu 5400 Arithmetic Sequence