关于UITabBarController (非自定义)


本文所提到的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  不能改变 高度, 还文字和图片的相对位置, 如果要改,还是需要自定义。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值