UISegmentedControl分段控制器

{
   // 注意: 顺序(类似压栈的方式)
   // 创建VC对象
    self.gameVC = [[GameListViewController alloc] init];
    [self addChildViewController:self.gameVC];
    [self.view addSubview:self.gameVC.view];

    self.TVVC = [[TVListViewController alloc] init];
    [self addChildViewController:self.TVVC];
    [self.view addSubview:self.TVVC.view];

    self.movieVC = [[MovieListViewController alloc] init];
    [self addChildViewController:self.movieVC];
    [self.view addSubview:self.movieVC.view];


    self.view.backgroundColor = [UIColor whiteColor];

    [self setAutomaticallyAdjustsScrollViewInsets:NO];


    // 创建分段控制器对象
    UISegmentedControl *segmentC = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"综艺", @"电视", @"游戏", nil]];
    segmentC.backgroundColor = [UIColor groupTableViewBackgroundColor];
    // 定位置
    segmentC.frame = CGRectMake(100 * k_WIDTH, 30 * k_HEIGHT, 210 * k_WIDTH, 30 * k_HEIGHT);
    // 设置圆角
    segmentC.layer.masksToBounds = YES;
    segmentC.layer.cornerRadius = 5;
    // 设置颜色
    segmentC.layer.borderColor = [UIColor colorWithRed:1.000 green:0.502 blue:0.000 alpha:1.000].CGColor;
    // 设置边框粗细
    segmentC.layer.borderWidth = 1;

    // 设置默认0
    segmentC.selectedSegmentIndex = 0;

    self.navigationItem.titleView = segmentC;

    [segmentC addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];

}

// segment点击事件实现方法
- (void)segmentAction:(UISegmentedControl *)segment {

    // 如果是0 就进入综艺界面
    if (segment.selectedSegmentIndex == 0) {
        [self.view bringSubviewToFront:self.movieVC.view];
    }

    if (segment.selectedSegmentIndex == 1) {
        [self.view bringSubviewToFront:self.TVVC.view];
    }

    if (segment.selectedSegmentIndex == 2) {
        [self.view bringSubviewToFront:self.gameVC.view];
    }


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值