iOS-新手引导页+标签控制器

AppDelegate.h

#import "ViewController.h"
#import "MenuViewController.h"


@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@property (readonly, strong) NSPersistentContainer *persistentContainer;
@property (nonatomic,strong)MenuViewController *vc;
@property (nonatomic,strong)UITabBarController *tabBarCtl;//标签栏控制器

AppDelegate.m

#import "GuideViewController.h"
#import "MenuViewController.h"
#import "MeViewController.h"
#import "TopicViewController.h"


@interface AppDelegate ()

@end

@implementation AppDelegate
//私有方法,用于生成一个导航控制器
- (UINavigationController *)createNavigationWithController:(UIViewController *)vc title:(NSString *)title image:(NSString *)imgName selectImage:(NSString *)selectImgName{

    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc];
    vc.navigationItem.title = title;
    nav.tabBarItem = [[UITabBarItem alloc]initWithTitle:title image:[UIImage imageNamed:imgName] selectedImage:[UIImage imageNamed:selectImgName]];


    return nav;
}


//标签栏控制器
- (UITabBarController *)tabBarCtl{
    if (!_tabBarCtl) {
        _tabBarCtl = [[UITabBarController alloc]init];
        self.tabBarCtl.tabBar.tintColor = [UIColor blackColor];
        UINavigationController *homeNav = [self createNavigationWithController:[[MenuViewController alloc]init] title:@"头条" image:@"main_bottom_tab_recipe_gray_25x25_" selectImage:@"main_bottom_tab_recipe_red_25x25_"];
        UINavigationController *selectNav = [self createNavigationWithController:[[TopicViewController alloc]init] title:@"小组" image:@"main_bottom_tab_pai_gray_25x25_" selectImage:@"main_bottom_tab_pai_red_25x25_"];

        UINavigationController *myNav = [self createNavigationWithController:[[MeViewController alloc]init] title:@"我的" image:@"main_bottom_tab_user_gray_25x25_" selectImage:@"main_bottom_tab_user_red_25x25_"];

        _tabBarCtl.viewControllers = @[homeNav,selectNav,myNav];

        [[UITabBar appearance] setTintColor:[UIColor colorWithRed:252/255.0  green:104/255.0  blue:106/255.0 alpha:1]];

        //设置导航的背景颜色
        [UINavigationBar appearance].barTintColor=[UIColor colorWithRed:252/255.0  green:104/255.0  blue:106/255.0 alpha:1];




    }
    return _tabBarCtl;
}




- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.


    GuideViewController *guideVC = [[GuideViewController alloc]init];
    self.vc = [[MenuViewController alloc]init];
    //第一次运行app
    if (![[NSUserDefaults standardUserDefaults]objectForKey:NOT_FIRST_LANUCH]) {
        self.window.rootViewController = guideVC;
    }
    //非首次运行app
    else{
        //获取当前的版本号

        //获取持久化的版本号数据
        NSString *savedVersion =  [[NSUserDefaults standardUserDefaults]objectForKey:NOT_FIRST_LANUCH];
        //判断版本号是否一致
        if ([savedVersion isEqualToString:VERSION_CURRENT]) {
            //没有更新
            self.window.rootViewController = self.vc;
        }
        else{
            //更新了
            self.window.rootViewController = guideVC;
        }
    }




    return YES;
}

GuideViewController.m

#import "ImageScrollView.h"
#import "AppDelegate.h"
@interface GuideViewController ()<ImageScrollViewDelegate>

@end

@implementation GuideViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.


    self.view.backgroundColor = [UIColor whiteColor];

    NSArray *imgArr = @[@"新手引导页5.jpg",@"新手引导页4.jpg",@"首页.jpg"];
    ImageScrollView *imgScrView  = [[ImageScrollView alloc]initWithFrame:CGRectNull style:ImageScrollType_Guide images:imgArr confirmBtnTitle:@"立即体验" confirmBtnTitleColor:[UIColor redColor] confirmBtnFrame:CGRectMake(230, 10, 100, 40) autoScrollTimeInterval:0 delegate:self];


    [self.view addSubview:imgScrView];
    [imgScrView addPageControlToSuperView:self.view];


}

#pragma mark -ImageScrollViewDelegate
- (void)experienceDidHandle{
    //获取当前的版本号,持久化
    NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
    [ud setObject:VERSION_CURRENT forKey:NOT_FIRST_LANUCH];
    [ud synchronize];

    //切换窗口的根视图控制器
    AppDelegate *app = App_Delegate;
    app.window.rootViewController = app.vc;

}

MenuViewController.m

  self.view.backgroundColor = [UIColor whiteColor];
        AppDelegate *app = App_Delegate;
        app.window.rootViewController = app.tabBarCtl;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值