ios 饿

AppDelegate.m 里面

#import "myViewController.h"

#import "ViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

NSUserDefaults *useDef = [NSUserDefaults standardUserDefaults];

// 使用 NSUserDefaults 读取用户数据

if (![useDef boolForKey:@"notFirst"]) {

// 如果是第一次进入引导页

_window.rootViewController = [[myViewController alloc] init];

}

else{

// 否则直接进入应用

_window.rootViewController = [[ViewController alloc] init];

}

return YES;

}

myViewController.m中

#import "myViewController.h"

#import "ViewController.h"

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

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

@interface myViewController ()

{

// 创建页码控制器

UIPageControl *pageControl;

// 判断是否是第一次进入应用

BOOL flag;

}

@property (nonatomic,strong) NSTimer *timer;

@end

@implementation myViewController

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

_timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(tiao) userInfo:nil repeats:NO];

UIScrollView *myScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];

for (int i=0; i<2; i++) {

UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",i+1]];

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH * i, 0, WIDTH, HEIGHT)];

// 在最后一页创建按钮

if (i == 1) {

// 必须设置用户交互 否则按键无法操作

imageView.userInteractionEnabled = YES;

UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];

button.frame = CGRectMake(WIDTH / 3, HEIGHT * 7 / 8, WIDTH / 3, HEIGHT / 16);

[button setTitle:@"点击进入" forState:UIControlStateNormal];

[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

button.layer.borderWidth = 2;

button.layer.cornerRadius = 5;

button.backgroundColor = [UIColor whiteColor];

button.clipsToBounds = YES;

button.layer.borderColor = [UIColor whiteColor].CGColor;

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

[imageView addSubview:button];

}

imageView.image = image;

[myScrollView addSubview:imageView];

}

myScrollView.bounces = NO;

myScrollView.pagingEnabled = YES;

myScrollView.showsHorizontalScrollIndicator = NO;

myScrollView.contentSize = CGSizeMake(WIDTH * 2, HEIGHT);

myScrollView.delegate = self;

[self.view addSubview:myScrollView];

pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(WIDTH / 3, HEIGHT * 15 / 16, WIDTH / 3, HEIGHT / 16)];

// 设置页数

pageControl.numberOfPages = 2;

// 设置页码的点的颜色

pageControl.pageIndicatorTintColor = [UIColor yellowColor];

// 设置当前页码的点颜色

pageControl.currentPageIndicatorTintColor = [UIColor redColor];

[self.view addSubview:pageControl];

}

#pragma mark - UIScrollViewDelegate

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{

// 计算当前在第几页

pageControl.currentPage = (NSInteger)(scrollView.contentOffset.x / [UIScreen mainScreen].bounds.size.width);

}

- (void)tiao

{

flag = YES;

NSUserDefaults *useDef = [NSUserDefaults standardUserDefaults];

// 保存用户数据

[useDef setBool:flag forKey:@"notFirst"];

[useDef synchronize];

// 切换根视图控制器

self.view.window.rootViewController = [[ViewController alloc] init];

}

// 点击按钮保存数据并切换根视图控制器

- (void) go:(UIButton *)sender{

flag = YES;

NSUserDefaults *useDef = [NSUserDefaults standardUserDefaults];

// 保存用户数据

[useDef setBool:flag forKey:@"notFirst"];

[useDef synchronize];

// 切换根视图控制器

self.view.window.rootViewController = [[ViewController alloc] init];

}

@end

ViewController.m

#import "ViewController.h"

#import "FirstViewController.h"

#import "SecViewController.h"

#import "ThirdViewController.h"

#import "FourViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

//将四个页面初始化

FirstViewController *firstVC = [[FirstViewController 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:@""] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

firstNav.tabBarItem.selectedImage = [[UIImage imageNamed:@""] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

SecViewController *secVC = [[SecViewController 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:@""] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

secNav.tabBarItem.selectedImage = [[UIImage imageNamed:@""] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

ThirdViewController *thirdVC = [[ThirdViewController 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:@""] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

thirdNav.tabBarItem.selectedImage = [[UIImage imageNamed:@""] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

FourViewController *fourVC = [[FourViewController alloc]init];

UINavigationController *fourNav = [[UINavigationController alloc]initWithRootViewController:fourVC];

fourNav.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:@""] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

fourNav.tabBarItem.selectedImage = [[UIImage imageNamed:@""] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

//添加其他主页面

self.viewControllers = @[firstNav,secNav,thirdNav,fourNav];

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

@end

FirstViewController.m中

#import "UISearchBar+FMAdd.h"

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

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

@interface FirstViewController ()

{

UIPageControl *pageControl;

}

@property (nonatomic,strong) UITableView *tableView;

@property (nonatomic,strong) UIView *headView;

@property (nonatomic,strong) UISearchBar *searchBar;

@property(nonatomic,strong)UIButton *button;

@end

@implementation FirstViewController

- (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;

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;

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

你可能感兴趣的:(ios 饿)