ViewController.m

#import "ViewController.h"
#import "yinViewController.h"

@interface ViewController ()<UIScrollViewDelegate>{
    
    //实现三个属性
    
    UIScrollView *scroll;
    
    NSArray *imgArr;//图片
    
    UIPageControl *page;//页面
    
}

@end

@implementation ViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    //self.view.backgroundColor = [UIColor whiteColor];
    
    scroll = [[UIScrollView alloc]initWithFrame:self.view.frame];
    
    //添加协议
    
    scroll.delegate = self;
    
    [self.view addSubview:scroll];
    
    imgArr = @[@"timg.jpg",@"timg.jpg",@"timg.jpg",@"timg.jpg"];
    
    //设置图片进行滚动
    
    scroll.pagingEnabled = YES;
    
    for (int i = 0; i < imgArr.count; i++)
        
    {
        
        UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(scroll.frame.size.width * i, 0, self.view.frame.size.width, self.view.frame.size.height)];
        
        img.userInteractionEnabled = YES;
        
        if (i == imgArr.count - 1)
            
        {
            
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
            
            [btn setTitle:@"立即体验" forState:UIControlStateNormal];
            
            btn.frame = CGRectMake((self.view.frame.size.width -100) / 2 , 600 , 100, 44);
            
            [btn addTarget:self action:@selector(Click) forControlEvents:UIControlEventTouchUpInside];
            
            btn.layer.cornerRadius = 10;
            
            btn.layer.masksToBounds = YES;
            
            btn.backgroundColor = [UIColor redColor];
            
            [img addSubview:btn];
            
        }
        
        img.image = [UIImage imageNamed:imgArr[i]];
        
        [scroll addSubview:img];
        
    }
    
    scroll.contentSize = CGSizeMake(self.view.frame.size.width * imgArr.count, self.view.frame.size.height);
    
    //取消弹簧效果
    
    scroll.bounces = NO;
    
    //隐藏滚动条
    
    scroll.showsHorizontalScrollIndicator = NO;
    
    //页码  (点)
    
    page = [[UIPageControl alloc]initWithFrame:CGRectMake((self.view.frame.size.width -100) / 2, 536, 100, 20)];
    
    page.numberOfPages = imgArr.count;
    
    //设置初始页码
    
    page.currentPage = 0;
    
    //设置页码的颜色
    
    page.pageIndicatorTintColor = [UIColor yellowColor];
    
    [self.view addSubview:page];
    
}

#pragma -

#pragma mark -UIScrollViewDelegate

-(void)scrollViewDidScroll:(UIScrollView *)scrollView

{
    
    NSLog(@"contentOffset: x: %f,y: %f",scrollView.contentOffset.x,scrollView.contentOffset.y);
    
    //求余
    
    NSInteger index = scroll.contentOffset.x / scrollView.frame.size.width;
    
    page.currentPage = index;
    
}

- (void)Click{
    
    yinViewController *mc = [[yinViewController alloc]init];
    
    [self presentViewController:mc animated:YES completion:^{
        
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end

import "yinViewController.h"

#import "mainViewController.h"
#import "waiMaiViewController.h"
#import "FineViewController.h"
#import "dingDanViewController.h"

@interface yinViewController ()

@end

@implementation yinViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    //将四个页面初始化
    
    mainViewController *firstVC = [[mainViewController alloc]init];
    
    UINavigationController *firstNav = [[UINavigationController alloc]initWithRootViewController:firstVC];
    
    firstVC.view.backgroundColor = [UIColor whiteColor];
    
    firstNav.navigationBar.barTintColor = [UIColor colorWithRed:(64.0/255.0) green:(143.0/255.0) blue:(236.0/255.0) alpha:1.0];
    
    firstNav.tabBarItem.title = @"外卖";
    
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:(64.0/255.0) green:(143.0/255.0) blue:(236.0/255.0) alpha:1.0],NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];
    
    firstNav.tabBarItem.image = [[UIImage imageNamed:@"live_height"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    firstNav.tabBarItem.selectedImage = [[UIImage imageNamed:@"live"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    waiMaiViewController *secVC = [[waiMaiViewController alloc]init];
    
    UINavigationController *secNav = [[UINavigationController alloc]initWithRootViewController:secVC];
    
    secVC.view.backgroundColor = [UIColor colorWithRed:(238.0/255.0) green:(238.0/255.0) blue:(238.0/255.0) alpha:1.0];
    
    secNav.tabBarItem.title = @"发现";
    
    secNav.tabBarItem.image = [[UIImage imageNamed:@"my_height"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    secNav.tabBarItem.selectedImage = [[UIImage imageNamed:@"my"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    FineViewController *thirdVC = [[FineViewController alloc]init];
    
    UINavigationController *thirdNav = [[UINavigationController alloc]initWithRootViewController:thirdVC];
    
    thirdVC.view.backgroundColor = [UIColor colorWithRed:(238.0/255.0) green:(238.0/255.0) blue:(238.0/255.0) alpha:1.0];
    
    thirdNav.tabBarItem.title = @"订单";
    
    thirdNav.tabBarItem.image = [[UIImage imageNamed:@"news_height"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    thirdNav.tabBarItem.selectedImage = [[UIImage imageNamed:@"news"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    dingDanViewController *fourVC = [[dingDanViewController alloc]init];
    
    UINavigationController *fourNav = [[UINavigationController alloc]initWithRootViewController:fourVC];
    
    fourVC.view.backgroundColor = [UIColor colorWithRed:(238.0/255.0) green:(238.0/255.0) blue:(238.0/255.0) alpha:1.0];
    
    fourNav.tabBarItem.title = @"我的";
    
    fourNav.tabBarItem.image = [[UIImage imageNamed:@"tittle_height"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    fourNav.tabBarItem.selectedImage = [[UIImage imageNamed:@"tittle"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    
    //添加其他主页面
    self.viewControllers = @[firstNav,secNav,thirdNav,fourNav];
}
@end

import "mainViewController.h"

#import "mainViewController.h"

#define WIDTH (NSInteger)self.view.bounds.size.width

#define HEIGHT (NSInteger)self.view.bounds.size.height

@interface mainViewController ()<UITableViewDelegate,UITableViewDataSource,UISearchBarDelegate,UIScrollViewDelegate>{
    
    UIPageControl *pageControl;
    
}

@property (nonatomic,strong) UITableView *tableView;

@property (nonatomic,strong) UIView *headView;

@property (nonatomic,strong) UISearchBar *searchBar;

@property(nonatomic,strong)UIButton *button;

@end

@implementation mainViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 180, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];
    
    _tableView.delegate = self;
    
    _tableView.dataSource = self;
    
    [self.view addSubview:_tableView];
    
    _headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];
    
    _headView.backgroundColor = [UIColor colorWithRed:(64.0/255.0) green:(143.0/255.0) blue:(236.0/255.0) alpha:1.0];
    
    [self.view addSubview:_headView];
    
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 40, self.view.frame.size.width/2, 40)];
    
    titleLabel.text = @"饿了就上饿了么";
    
    titleLabel.textColor = [UIColor whiteColor];
    
    titleLabel.font = [UIFont systemFontOfSize:20];
    
    [self.view addSubview:titleLabel];
    
    UILabel *subLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 70, self.view.frame.size.width/2, 40)];
    
    subLabel.text = @"八维研修学院(第二校区)";
    
    subLabel.textColor = [UIColor whiteColor];
    
    subLabel.font = [UIFont systemFontOfSize:15];
    
    [self.view addSubview:subLabel];
    
    _searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 120, self.view.frame.size.width, 60)];
    
    _searchBar.delegate = self;
    
    //设置背景图是为了去掉上下黑线
    
    _searchBar.backgroundImage = [[UIImage alloc] init];
    
    // 设置SearchBar的颜色主题为白色
    
    _searchBar.barTintColor = [UIColor whiteColor];
    
    UITextField *searchField = [_searchBar valueForKey:@"searchField"];
    
    if (searchField) {
        
        [searchField setBackgroundColor:[UIColor whiteColor]];
        
        searchField.layer.cornerRadius = 14.0f;
        
        searchField.layer.borderColor = [UIColor colorWithRed:64.0/255.0 green:143.0/255.0 blue:236.0/255.0 alpha:1].CGColor;
        
        searchField.layer.borderWidth = 1;
        
        searchField.layer.masksToBounds = YES;
        
    }
    
    searchField.placeholder = @"输入商家、商品名称";
    
    [self.view addSubview:_searchBar];
    
    NSArray *titleArr = @[@"西瓜",@"醉唐轩",@"三元",@"加班食补",@"我的菜",@"红烧肉",@"肯德基",@"庆丰"];
    
    for (int i =0; i<8 ; i++) {
        
        UIButton *btn1 = [[UIButton alloc]initWithFrame:CGRectMake(i * 50, 170, 50, 20)];
        
        [btn1 setTitle:[NSString stringWithFormat:@"%@", titleArr[i]] forState:UIControlStateNormal];
        
        btn1.titleLabel.font= [UIFont systemFontOfSize:12];
        
        btn1.tag = i;
        
        [btn1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        
        [self.view addSubview:btn1];
        
    }
    
    self.button = [UIButton buttonWithType:UIButtonTypeRoundedRect];

    self.button.frame = CGRectMake(100, 100, 50, 50);

    [self.button setImage:[[UIImage imageNamed:@"shopCar"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];

    [self.button addTarget:self action:@selector(dragMoving:withEvent: )forControlEvents: UIControlEventTouchDragInside];

    [self.button addTarget:self action:@selector(dragEnded:withEvent: )forControlEvents:UIControlEventTouchUpOutside];

    [self.button addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];

    [self.view addSubview:self.button];

    [_button bringSubviewToFront:self.view];
    
}

- (void) dragMoving: (UIControl *) c withEvent:ev{
    
    c.center = [[[ev allTouches] anyObject] locationInView:self.view];
    
}

- (void) dragEnded: (UIControl *) c withEvent:ev{
    
    c.center = [[[ev allTouches] anyObject] locationInView:self.view];
    
}

-(void)buttonAction:(UIButton *)sender{
    
}

- (UIStatusBarStyle)preferredStatusBarStyle{

    return UIStatusBarStyleLightContent;

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 3;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    NSInteger row = 0;
    
    NSInteger sect = section;
    
    switch (sect) {
            
        case 0:
            
            row = 2;
            
            break;
            
        case 1:
            
            row = 2;
            
            break;
            
        case 2:
            
            row = 1;
            
            break;
            
        default:
            
            break;
            
    }
    
    return row;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    if (!cell) {
        
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        
    }
    
    if (indexPath.section ==0) {
        
        if (indexPath.row ==0) {
            
            UIScrollView *myScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH * 2, 200)];
            
            for (int i=0; i<2; i++) {
                
                UIView *View = [[UIView alloc] initWithFrame:CGRectMake(WIDTH * i, 0, WIDTH, 200)];
                
                // 在最后一页创建按钮
                
                [myScrollView addSubview:View];
                
            }
            
            myScrollView.bounces = NO;
            
            myScrollView.pagingEnabled = YES;
            
            myScrollView.showsHorizontalScrollIndicator = NO;
            
            myScrollView.contentSize = CGSizeMake(WIDTH * 2, HEIGHT);
            
            myScrollView.delegate = self;
            
            [cell addSubview:myScrollView];
            
            pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(WIDTH /3, 170, WIDTH / 3, 40)];
            
            // 设置页数
            
            pageControl.numberOfPages = 2;
            
            // 设置页码的点的颜色
            
            pageControl.pageIndicatorTintColor = [UIColor yellowColor];
            
            // 设置当前页码的点颜色
            
            pageControl.currentPageIndicatorTintColor = [UIColor redColor];
            
            [cell addSubview:pageControl];
            
        }
        
    }
    
    return cell;
    
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    // 计算当前在第几页
    
    pageControl.currentPage = (NSInteger)(scrollView.contentOffset.x / [UIScreen mainScreen].bounds.size.width);
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    CGFloat cellHight = 0.0;
    
    NSInteger sect = indexPath.section;
    
    NSInteger row = indexPath.row;
    
    switch (sect) {
            
        case 0:
            
            switch (row) {
                    
                case 0:
                    
                    cellHight = 200;
                    
                    break;
                    
                case 1:
                    
                    cellHight = 100;
                    
                    break;
                    
                default:
                    
                    break;
                    
            }
            
            break;
            
        case 1:
            
            switch (row) {
                    
                case 0:
                    
                    cellHight = 50;
                    
                    break;
                    
                case 1:
                    
                    cellHight = 50;
                    
                    break;
                    
                default:
                    
                    break;
                    
            }
            
            break;
            
        case 2:
            
            cellHight = 180;
            
            break;
            
        default:
            
            break;
            
    }
    
    return cellHight;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 0.1;
    
}

- (void)viewWillAppear:(BOOL)animated{
    
    self.navigationController.navigationBarHidden = YES;
    
}
@end

import "waiMaiViewController.h"

#import "waiMaiViewController.h"

@interface waiMaiViewController ()

@end

@implementation waiMaiViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor greenColor];
}
@end
#import "FineViewController.h"

@interface FineViewController ()

@end

@implementation FineViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor redColor];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#import "dingDanViewController.h"

@interface dingDanViewController ()

@end

@implementation dingDanViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor blueColor];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 206,602评论 6 481
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 88,442评论 2 382
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 152,878评论 0 344
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 55,306评论 1 279
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 64,330评论 5 373
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,071评论 1 285
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,382评论 3 400
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,006评论 0 259
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,512评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,965评论 2 325
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,094评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,732评论 4 323
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,283评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,286评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,512评论 1 262
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,536评论 2 354
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,828评论 2 345

推荐阅读更多精彩内容