iOS学习笔记-092.彩票07——竞技场

彩票07——竞技场

一、图示

这里写图片描述


二、界面分析

首先来看背景,背景是一张图片,我们可以创建一个 ImageView 来设置背景,让它能够交互

第二、我们发现我们的 导航条 和其他是不一样的,那么我们可以定制一下我们的 导航控制器(QWMArenaNavigationController)。修改我们的导航条的背景。

第三、选项卡的问题,上面的选项卡我们可以在控制器中创建 UISegmentedControl,然后添加到导航条中。

第四、在 QWMTabBarViewController 创建导航控制器的时候,竞技场 使用我们的 导航控制器。


三、QWMArenaViewController.m

这个类是竞技场的控制器,这个控制器里面我们主要 创建背景和设置我们的选项卡。

//
//  QWMArenaViewController.m
//  03_UIView79_彩票
//
//  Created by 杞文明 on 17/7/24.
//  Copyright © 2017年 杞文明. All rights reserved.
//

#import "QWMArenaViewController.h"

@interface QWMArenaViewController ()

@end

@implementation QWMArenaViewController

// 当第一次加载view的时候调用
// 如果自定义view,重写这个方法
-(void)loadView{
    // 在这个方法里面不能调用self.view.bounds,如果调用会造成死循环
    //创建UIImageView
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.view = imageView;

    //设置背景图片
    imageView.image = [UIImage imageNamed:@"NLArenaBackground"];

    //设置允许与用户交互
    imageView.userInteractionEnabled = YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    //1.设置titleView
    UISegmentedControl *segmentedControl = [[UISegmentedControl alloc]initWithItems:@[@"足球",@"篮球"]];

    //2.设置背景图片
    //普通状态
    [segmentedControl setBackgroundImage:[UIImage imageNamed:@"CPArenaSegmentBG"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    //选中状态
    [segmentedControl setBackgroundImage:[UIImage imageNamed:@"CPArenaSegmentSelectedBG"] forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];

    //3.设置字体颜色
    [segmentedControl setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]} forState:UIControlStateNormal];

    //4/设置选中的索引
    segmentedControl.selectedSegmentIndex = 0;

    //5.设置前景色
    segmentedControl.tintColor = [UIColor colorWithRed:0 green:142/255.0 blue:143/255.0 alpha:1];

    self.navigationItem.titleView = segmentedControl;
}

@end

四、QWMArenaNavigationController.m

这个是竞技场的导航控制器,修改导航条的背景。

//
//  QWMArenaNavigationController.m
//  03_UIView79_彩票
//
//  Created by 杞文明 on 17/8/24.
//  Copyright © 2017年 杞文明. All rights reserved.
//

#import "QWMArenaNavigationController.h"

@interface QWMArenaNavigationController ()

@end

@implementation QWMArenaNavigationController

+(void)initialize{
    //1.获取导航条标识
    UINavigationBar *bar = [UINavigationBar appearanceWhenContainedIn:self, nil];

    //2.设置导航条背景色
    UIImage *image = [UIImage imageNamed:@"NLArenaNavBar64"];
    image = [image stretchableImageWithLeftCapWidth:image.size.width/2 topCapHeight:image.size.height/2];
    [bar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
}

@end

五、QWMTabBarViewController.m 修改

在 QWMTabBarViewController 创建导航控制器的时候,竞技场 使用我们的 QWMArenaNavigationController 导航控制器

如下面

//
//  QWMTabBarViewController.m
//  03_UIView79_彩票
//
//  Created by 杞文明 on 17/7/24.
//  Copyright © 2017年 杞文明. All rights reserved.
//

#import "QWMTabBarViewController.h"
#import "QWMHallTableViewController.h"
#import "QWMArenaViewController.h"
#import "QWMDiscoverTableViewController.h"
#import "QWMHistoryTableViewController.h"
#import "QWMMyLotteryViewController.h"
#import "QWMTabBar.h"
#import "QWMNavigationController.h"
#import "QWMArenaNavigationController.h"

@interface QWMTabBarViewController ()<QWMTabBarDelegate>
/** taBBar item 模型数组 */
@property (nonatomic, strong) NSMutableArray *items;
@end

@implementation QWMTabBarViewController


......

//添加一个子控制器
-(void)setupOneChildViewController:(UIViewController *)vc image:(UIImage *)image selImage:(UIImage *)selImage title:(NSString *)title{
//    [self addChildViewController:vc];

    //设置我们控制器的一些属性
    vc.tabBarItem.image = image;
    vc.tabBarItem.selectedImage = selImage;
    [self.items addObject:vc.tabBarItem];
    //添加标题
    vc.navigationItem.title = title;

    //创建自己的导航条
    UINavigationController *nav;
    if([vc isKindOfClass:[QWMArenaViewController class]]){
        //如果是竞技场,我们使用 竞技场导航控制器
        nav = [[QWMArenaNavigationController alloc]initWithRootViewController:vc];
    }else{
        nav = [[QWMNavigationController alloc]initWithRootViewController:vc];
    }

    [self addChildViewController:nav];
}
.....
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值