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.
}
网友评论