滚动视图(切换)

//自己创建类
#import “SlideSwitchExample1.h”
#import “TouTiaoViewController.h”
#import “ShipinViewController.h”
#import “BeijingViewController.h”
#import “CepingViewController.h”
#import “DaogouViewController.h”
#import “XincheViewController.h”
#import “WancheViewController.h”
#import “ShuocheViewController.h”
#import “WenzhangViewController.h”

//第三方导入
#import “CKSlideMenu.h”

@interface SlideSwitchExample1 ()

@end

@implementation SlideSwitchExample1

  • (void)viewDidLoad {
    [super viewDidLoad];
    [self buildUI];
    }

  • (void)buildUI {
    self.view.backgroundColor = [UIColor whiteColor];
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(370,20, 40,40)];
    [btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(btn) forControlEvents:UIControlEventTouchUpInside];
    btn.backgroundColor = [UIColor orangeColor];
    [btn setTitle:@“➕” forState:UIControlStateNormal];

    //要显示的标题
    NSArray *titles = @[@“头条”,@“视频”,@“北京”,@“测评”,@“导购”,@“新车”,@“玩车”,@“说车”,@“文章”];
    //创建需要展示的ViewController
    NSMutableArray *viewControllers = [[NSMutableArray alloc] init];
    for (NSInteger i = 0 ; i<titles.count; i++) {
    UIViewController *vc = [self viewControllerOfIndex:i];
    [viewControllers addObject:vc];
    }
    CKSlideMenu *slideMenu = [[CKSlideMenu alloc]initWithFrame:CGRectMake(0, 20, self.view.frame.size.width-60, 40) titles:titles controllers:viewControllers];
    slideMenu.bodyFrame = CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height);
    slideMenu.bodySuperView = self.view;
    slideMenu.indicatorStyle = SlideMenuIndicatorStyleFollowText;
    slideMenu.indicatorOffsety = 0;
    slideMenu.titleStyle = SlideMenuTitleStyleAll;
    slideMenu.indicatorHeight = 2;
    slideMenu.showIndicator = NO;
    [self.view addSubview:slideMenu];
    [self.view addSubview:btn];
    }

  • (UIButton *)moreButton {
    UIButton *button = [[UIButton alloc] init];
    [button setTitle:@“➕” forState:UIControlStateNormal];
    [button addTarget:self action:@selector(btn) forControlEvents:UIControlEventTouchUpInside];
    // [button setImageEdgeInsets:UIEdgeInsetsMake(8, 8, 8, 8)];
    return button;
    }

  • (UIViewController *)viewControllerOfIndex:(NSInteger)index {
    UIViewController *vc;
    switch (index%2) {
    case 0:
    vc = [[TouTiaoViewController alloc] init];
    break;
    case 1:
    vc = [[ShipinViewController alloc] init];
    break;
    case 2:
    vc = [[BeijingViewController alloc] init];
    break;
    case 3:
    vc = [[CepingViewController alloc] init];
    break;
    case 4:
    vc = [[DaogouViewController alloc] init];
    break;
    case 5:
    vc = [[XincheViewController alloc] init];
    break;
    case 6:
    vc = [[WancheViewController alloc] init];
    break;
    case 7:
    vc = [[ShuocheViewController alloc] init];
    break;
    case 8:
    vc = [[WenzhangViewController alloc] init];
    break;
    default:
    break;
    }
    return vc;
    }

  • (void)btn{
    NSLog(@“1221”);
    }
    //隐藏系统导航栏

  • (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];//调用父类方法
    self.navigationController.navigationBarHidden = YES;
    //更改状态栏样式
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;

}
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];//调用父类方法
self.navigationController.navigationBarHidden = NO;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值