美文网首页
页面滚动按钮(导航栏下边)

页面滚动按钮(导航栏下边)

作者: 盖世英雄的梦想 | 来源:发表于2018-12-04 09:42 被阅读0次

首先我们先导入XLSlideSwitch,
然后我们创建六个viewcontroller,
然后就是在AppDelegate创建导航栏
再然后就是在主视图里写代码了:

先导入那六个viewcontroller的头文件,然后遵守协议<XLSlideSwitchDelegate>

{
UIView *SomeView; ///是点击加号按钮出现的View
UIButton *Btn; ///按钮
}
@property (nonatomic , strong)XLSlideSwitch *ScrollView;///滚动视图

viewDidLoad里写

///创建一个数组用来存储名字
NSArray *TitlesArr = @[@"推荐" , @"热门" ,@"搞笑" , @"军事" , @"社会" , @"音乐"];
// !!!!!用来存储六个类的名字 需要更改!!!!!!
NSArray *ControllersArr = @[@"yidongtongxunViewController" , @"chuanmeiViewController" , @"ruangongViewController" , @"wanggonViewController" , @"yunjisViewController" , @"jianzhuViewController"];
NSMutableArray *ViewControllers = [[NSMutableArray alloc] init];
for (int i = 0 ; i < TitlesArr.count; i ++) {
//字符串创建控制器
UIViewController *VC = [[NSClassFromString(ControllersArr[i])alloc] init];
[ViewControllers addObject:VC];
}
//滚动视图
_ScrollView = [[XLSlideSwitch alloc] initWithFrame:CGRectMake(0, 64, self.view.bounds.size.width, self.view.bounds.size.height - 64) Titles:TitlesArr viewControllers:ViewControllers];
_ScrollView.delegate = self;
_ScrollView.itemNormalColor = [UIColor darkGrayColor];
_ScrollView.itemSelectedColor = self.navigationController.navigationBar.tintColor;
_ScrollView.customTitleSpacing = 30;
_ScrollView.moreButton = [self moreButton];
[_ScrollView showInViewController:self];
// [_ScrollView showInNavigationController:self];
//View
SomeView = [[UIView alloc] initWithFrame:CGRectMake(self.view.bounds.size.width - 150, 104, 140, 200)];
SomeView.backgroundColor = [UIColor orangeColor];

for (int i = 0 ; i < 1; i ++) {
    [self.view addSubview:SomeView];
    SomeView.hidden = YES;
}

外边写

  • (UIButton *)moreButton{
    Btn = [[UIButton alloc] init];
    // [button setImage:[UIImage imageNamed:@"channelAdd"] forState:UIControlStateNormal];
    [Btn setTitle:@"➕" forState:UIControlStateNormal];
    [Btn setImageEdgeInsets:UIEdgeInsetsMake(8, 8, 8, 8)];
    [Btn addTarget:self action:@selector(BtnTouchUpInside) forControlEvents:UIControlEventTouchUpInside];
    return Btn;
    }

  • (void)BtnTouchUpInside{
    // NSLog(@"点击了添加按钮");
    if (Btn.selected == YES) {
    // SomeView.hidden = YES;
    Btn.selected = NO;
    SomeView.hidden = YES;
    }else{
    Btn.selected = YES;
    SomeView.hidden = NO;
    }
    }

相关文章

网友评论

      本文标题:页面滚动按钮(导航栏下边)

      本文链接:https://www.haomeiwen.com/subject/mlopcqtx.html