封装轮播图(没加定时器)

//
// FLLView.h
// 10-CustomCell-易车
//
// Created by LL.F on 16/7/27.
// Copyright © 2016年 LL.F. All rights reserved.
//

import <UIKit/UIKit.h>

@interface FLLView : UIView

@property (nonatomic, strong) UIButton *imageButton;
@property (nonatomic, strong) UILabel *bottomLabel;
- (void)setWithButtonImage:(NSString *)buttonImage
          bottomLabelText:(NSString *)bottomLabelText;

@end
//
// FLLView.m
// 10-CustomCell-易车
//
// Created by LL.F on 16/7/27.
// Copyright © 2016年 LL.F. All rights reserved.
//

import "FLLView.h"

@implementation FLLView

// 初始化
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        _imageButton = [UIButton buttonWithType:UIButtonTypeSystem];
        _imageButton.frame = CGRectMake(10, 10, 60, 60);
//        _imageButton.backgroundColor = [UIColor redColor];
        [self addSubview:_imageButton];
        
        _bottomLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 70, 90, 30)];
        _bottomLabel.textAlignment = 1;
        _bottomLabel.font = [UIFont systemFontOfSize:15];
//        _bottomLabel.backgroundColor = [UIColor blueColor];
        [self addSubview:_bottomLabel];
    }
    return self;
}
// 设置button图片和bottomLabel文字
- (void)setWithButtonImage:(NSString *)buttonImage bottomLabelText:(NSString *)bottomLabelText
{

    [_imageButton setImage:[[UIImage imageNamed:buttonImage] imageWithRenderingMode:1]forState:UIControlStateNormal];
    _bottomLabel.text = bottomLabelText;
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.

  • (void)drawRect:(CGRect)rect {
    // Drawing code
    }
    */

@end
//
// ViewController.m
// 10-CustomCell-易车
//
// Created by LL.F on 16/7/27.
// Copyright © 2016年 LL.F. All rights reserved.
//

import "ViewController.h"

import "FLLCycleImages.h"

import "FLLView.h"

import "ImageTableViewCell.h"

import "NormolTableViewCell.h"

import "CellModel.h"

define kScreenbounds [UIScreen mainScreen].bounds

define kScreenWidth [UIScreen mainScreen].bounds.size.width

define kScreenHeight [UIScreen mainScreen].bounds.size.height

@interface ViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataSource;
@property (nonatomic, strong) NSMutableArray *cycleArray;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //1.根据提供的Plist数据完成简易版易车界面(无图片显示)
    //注意: plist文件读取出来是个NSDictionary, 打印之后根据内容解析转换成相应的类
    //2.根据提供的Plist数据完成完整版易车界面(有图片显示并调研SDWebImage)
    
    // 初始化tableview
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
    
    [_tableView registerClass:[ImageTableViewCell class] forCellReuseIdentifier:@"imageCell"];
    [_tableView registerClass:[NormolTableViewCell class] forCellReuseIdentifier:@"normolCell"];
    
    // 数据解析
    self.dataSource = [NSMutableArray array];
    
    NSString *path = [[NSBundle mainBundle] pathForResource:@"YiChe" ofType:@"plist"];
    NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfFile:path];
    NSDictionary *dataDic = [dictionary objectForKey:@"data"];
    NSArray *listArray = [dataDic objectForKey:@"list"];
    for (NSDictionary *dic in listArray) {
        CellModel *model = [[CellModel alloc] init];
        [model setValuesForKeysWithDictionary:dic];
        [self.dataSource addObject:model];
    }
    //NSLog(@"%@", _dataSource);
    
    // 轮播图数据解析
    self.cycleArray = [NSMutableArray array];
    NSArray *cycleImageArray = [dataDic objectForKey:@"cycleImage"];
    for (NSDictionary *dic in cycleImageArray) {
        CellModel *model = [[CellModel alloc] init];
        [model setValuesForKeysWithDictionary:dic];
        NSLog(@"%@", model.picCover);
        [self.cycleArray addObject:model.picCover];
    }
    [_cycleArray removeLastObject];
    //NSLog(@"%@", _cycleArray);

}

// cell个数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return _dataSource.count;
    
}
// cell内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        ImageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"imageCell"];
        [cell.fllView1 setWithButtonImage:@"1" bottomLabelText:@"贷款买车"];
        [cell.fllView2 setWithButtonImage:@"2" bottomLabelText:@"直销车型"];
        [cell.fllView3 setWithButtonImage:@"3" bottomLabelText:@"低价买车"];
        [cell.fllView4 setWithButtonImage:@"4" bottomLabelText:@"二手车"];

    return cell;
    } else {
        NormolTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"normolCell"];
        CellModel *model = [self.dataSource objectAtIndex:indexPath.row];
        cell.model = model;
        
        return cell;
    }

    
}
// cell高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

    if (indexPath.row == 0) {
        
        return  100;
    } else
        
        return 80;
        
    
}
// 分区数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
  
    return 1;
    
}
// 头视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
// ***此处调用封装好的轮播图***
 // 轮播图
 FLLCycleImages *cycleImage = [[FLLCycleImages alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 200)];
 cycleImage.cycleScrollView.showsHorizontalScrollIndicator = YES;
 [self.view addSubview:cycleImage];
 NSArray *array = [NSArray arrayWithArray:_cycleArray];
//    NSArray *array = @[@"newsPic1", @"newsPic3", @"newsPic4"];
 [cycleImage setImagesWithArray:array];
 return cycleImage;
 ```

}
// 头视图高度

  • (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
    {

    return 200;
    }

  • (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    }
@end
// 运行效果如下, 以后涉及到轮播图, 直接引用封装好的文件调用即可.
![QQ0.png](http://upload-images.jianshu.io/upload_images/2435291-6871bbee5c52dab8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

推荐阅读更多精彩内容

  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥ios动画全貌。在这里你可以看...
    每天刷两次牙阅读 7,627评论 6 28
  • 1.oc基本语法 // // main.m // oc基本语法 // // Created by lanou on...
    GOT_HODOR阅读 256评论 0 0
  • 一:在ViewController中实例化MLPickerScrollView完成代理<MLPickerScrol...
    欧阳荣阅读 6,153评论 1 9
  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥iOS动画全貌。在这里你可以看...
    F麦子阅读 4,467评论 5 13
  • “我只是渔火,你是泡沫,运河上的起落,惹起了烟波,……念一首枫桥夜泊,你再不是我。”陶念耳朵里插着耳机,在苏州河边...
    贝塔BETA阅读 214评论 2 2
  • 睡觉前,看到朋友圈里发的一个标题为《雾霾侵入人体的全过程》的动画短视频。我突然萌发了一个念头,就拿这个动画视...
    六棱雪阅读 255评论 0 5
  • 查看vagrant box 添加vagrant box 创建一个vagrant box 查看状态 关机 暂停 回复...
    ShindouHikaru阅读 174评论 0 1
  • 不甘平庸又屈于平庸
    哈哈哈哈七阅读 107评论 0 0