您的位置:首页 > 产品设计 > UI/UE

关于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  不能改变 高度, 还文字和图片的相对位置, 如果要改,还是需要自定义。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: