//引导页,轮播图,网格视图
@property(nonatomic,strong)UIImageView *img;
@property(nonatomic,strong)UILabel *la;
-(instancetype)initWithFrame:(CGRect)frame
{
self=[super initWithFrame:frame];
if (self) {
self.img=[[UIImageView alloc]init];
[self.contentView addSubview:_img];
self.la=[[UILabel alloc]init];
[self.contentView addSubview:_la];
}
return self;
}
-(void)layoutSubviews
{
[super layoutSubviews];
self.img.frame=CGRectMake(13, 15, 50, 50);
self.la.frame=CGRectMake(0, 70, 75, 20);
self.la.textAlignment=NSTextAlignmentCenter;
self.la.font=[UIFont systemFontOfSize:13];
self.la.textColor=[UIColor lightGrayColor];
}
//uitableviewcell
@property(nonatomic,strong)UICollectionView *myCollectionView;
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
UICollectionViewFlowLayout *flow=[[UICollectionViewFlowLayout alloc]init];
flow.itemSize=CGSizeMake(70, 80);
flow.minimumLineSpacing=10;
flow.minimumInteritemSpacing=10;
flow.sectionInset=UIEdgeInsetsMake(15, 15, 15, 15);
flow.scrollDirection=UICollectionViewScrollDirectionHorizontal;
_myCollectionView =[[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.contentView.frame.size.width, 200) collectionViewLayout:flow];
[self.contentView addSubview:_myCollectionView];
}
return self;
}
- (void)layoutSubviews{
[super layoutSubviews];
_myCollectionView.frame = CGRectMake(0, 0, self.contentView.frame.size.width, 200);
}
- (void)awakeFromNib {
[super awakeFromNib];
}
//APPDelegate
#import "AppDelegate.h"
#import "GuideViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
GuideViewController *guideVC = [[GuideViewController alloc]init];
// 设置根视图控制器
self.window.rootViewController = guideVC;
return YES;
}
//页面效果
#import "ThirViewController.h"
#import "ImageScrollView.h"
#import "ViewController.h"
@interface ThirViewController ()
{
NSArray *imgArr;
NSArray *arr;
NSArray *arr1;
UITableView *tbv;
}
@end
static NSString *ID=@"ID";
@implementation ThirViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 图片数组
imgArr = @[@"1",@"2",@"3",@"4",@"5",@"6"];
self.view.backgroundColor = [UIColor whiteColor];
// 标题栏颜色
self.navigationController.navigationBar.barTintColor = [UIColor redColor];
self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"navigationItem_back"] style:UIBarButtonItemStylePlain target:self action:nil];
self.navigationItem.title = @"推荐";
//搜索条
UISearchBar *sea=[[UISearchBar alloc]init];
sea.delegate=self;
sea.layer.cornerRadius=10;
sea.layer.masksToBounds=YES;
sea.placeholder=@"星巴克送星意:礼券";
self.navigationItem.titleView=sea;
tbv = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
tbv.delegate = self;
tbv.dataSource = self;
[self.view addSubview:tbv];
tbv.tableHeaderView=img;
arr=@[@"美食",@"快餐小吃",@"签到",@"热门商圈",@"休闲娱乐",@"饿了么外卖",@"超市",@"KTV",@"丽人/美发",@"电影"];
arr1=@[@"美食",@"快餐",@"签到",@"热门",@"休闲",@"饿",@"超市",@"KTV",@"丽人",@"电影"];
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
return 2;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
if (section == 0) {
return 10;
}else{
return 10;
}
return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section==0) {
return 208;
}else if (indexPath.section==1)
{
return 300;
}else if (indexPath.section==2)
{
return 400;
}else if (indexPath.section==3)
{
return 300;
}
return 0;
}
// 设置行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
// 设置行高
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0) {
return 200;
}else{
return 100;
}
return 0;
}
// 设置cell内容
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *reuseID = @"cellID";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseID];
if (cell ==nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseID];
}
if (indexPath.section == 0) {
flowLayout=[[UICollectionViewFlowLayout alloc]init];
//设置滚动方向
flowLayout.scrollDirection=UICollectionViewScrollDirectionHorizontal;
flowLayout.itemSize=CGSizeMake(100,100);
//设置最小行间距
flowLayout.minimumLineSpacing=0;
//设置最小纵向行间距
flowLayout.minimumInteritemSpacing=0;
//创建网格视图
collectionView=[[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,200) collectionViewLayout:flowLayout];
//设置代理
collectionView.delegate=self;
collectionView.dataSource=self;
[collectionView registerClass:[MyCollectionViewCell class] forCellWithReuseIdentifier:ID];
collectionView.backgroundColor=[UIColor whiteColor];
[cell addSubview:collectionView];
}
if (indexPath.row == 0) {
// 自动滚动视图
ImageScrollView *img=[[ImageScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200) style:ImageScrollType_Banner images:imgArr confirmBtnTitle:nil confirmBtnTitleColor:nil confirmBtnFrame:CGRectMake(0, 0, 0, 0) autoScrollTimeInterval:1.0 delegate:self];
[cell addSubview:img];
}
return cell;
}
//内容
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
MyCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
cell.img.image = [UIImage imageNamed:arr1[indexPath.row]];
cell.la.text = arr[indexPath.row];
cell.backgroundColor = [UIColor whiteColor];
return cell;
}
//导航控制器
#import "GuideViewController.h"#import "ImageScrollView.h"#import "ViewController.h"#import "FirstViewController.h"#import "SecViewController.h"#import "ThirViewController.h"#import "FourViewController.h"@interface GuideViewController (){
NSArray *imgArr;
UITabBarController *tab;
SecViewController *secVC;
}
@end
@implementation GuideViewController
- (void)viewDidLoad {
[super viewDidLoad];
ViewController *VC = [[ViewController alloc]init];
UINavigationController *Nav = [[UINavigationController alloc]initWithRootViewController:VC];
Nav.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemMore tag:1];
FirstViewController *firVC = [[FirstViewController alloc]init];
UINavigationController *firNav = [[UINavigationController alloc]initWithRootViewController:firVC];
firNav.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemSearch tag:2];
secVC = [[SecViewController alloc]init];
UINavigationController *secNav = [[UINavigationController alloc]initWithRootViewController:secVC];
secNav.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemHistory tag:3];
ThirViewController *thirVC = [[ThirViewController alloc]init];
UINavigationController *thirNav = [[UINavigationController alloc]initWithRootViewController:thirVC];
thirNav.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemRecents tag:4];
FourViewController *fourVC = [[FourViewController alloc]init];
UINavigationController *fourNav = [[UINavigationController alloc]initWithRootViewController:fourVC];
fourNav.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemFeatured tag:5];
tab = [[UITabBarController alloc]init];
tab.viewControllers = @[Nav,secNav,thirNav,fourNav,firNav];
tab.selectedIndex = 2;
imgArr = @[@"111",@"222",@"333"];
ImageScrollView *guideScroll = [[ImageScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:ImageScrollType_Guide images:imgArr confirmBtnTitle:@"立即体验" confirmBtnTitleColor:[UIColor redColor] confirmBtnFrame:CGRectMake(200, 500, 100, 50) autoScrollTimeInterval:2.0 delegate:self];
[self.view addSubview:guideScroll];
}
-(void)experienceDidHandle
{
[self presentViewController:tab animated:YES completion:nil];
}
NSArray *imgName=@[@"guidePage1",@"guidePage2",@"guidePage3"];
CGRect confirmBtnFrame=CGRectMake(self.view.frame.size.width-200, 80, 150, 40);
ImageScrollView *guide=[[ImageScrollView alloc]initWithFrame:self.view.frame style:ImageScrollType_Guide images:imgName confirmBtnTitle:@"立即体验" confirmBtnTitleColor:[UIColor blackColor] confirmBtnFrame:confirmBtnFrame autoScrollTimeInterval:0 delegate:self];
//添加滚动视图
[self.view addSubview:guide];
//添加分页控件
[guide addPageControlToSuperView:self.view];
-(void)experienceDidHandle{
RootViewController *rootVC=[[RootViewController alloc]init];
AppDelegate *app=(AppDelegate *)[UIApplication sharedApplication].delegate;
app.window.rootViewController=rootVC;
}