您的位置:首页 > 移动开发 > IOS开发

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

2017-08-25 22:40 330 查看
彩票07竞技场
一图示

二界面分析

三QWMArenaViewControllerm

四QWMArenaNavigationControllerm

五QWMTabBarViewControllerm 修改

彩票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];
}
.....
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: