封裝輪播圖(沒加定時器)

//
// 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;
}
// 設(shè)置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.根據(jù)提供的Plist數(shù)據(jù)完成簡易版易車界面(無圖片顯示)
    //注意: plist文件讀取出來是個NSDictionary, 打印之后根據(jù)內(nèi)容解析轉(zhuǎn)換成相應的類
    //2.根據(jù)提供的Plist數(shù)據(jù)完成完整版易車界面(有圖片顯示并調(diào)研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"];
    
    // 數(shù)據(jù)解析
    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);
    
    // 輪播圖數(shù)據(jù)解析
    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個數(shù)
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return _dataSource.count;
    
}
// cell內(nèi)容
- (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;
        
    
}
// 分區(qū)數(shù)
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
  
    return 1;
    
}
// 頭視圖
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
// ***此處調(diào)用封裝好的輪播圖***
 // 輪播圖
 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
// 運行效果如下, 以后涉及到輪播圖, 直接引用封裝好的文件調(diào)用即可.
![QQ0.png](http://upload-images.jianshu.io/upload_images/2435291-6871bbee5c52dab8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • 在iOS中隨處都可以看到絢麗的動畫效果,實現(xiàn)這些動畫的過程并不復雜,今天將帶大家一窺ios動畫全貌。在這里你可以看...
    每天刷兩次牙閱讀 8,551評論 6 30
  • 1.oc基本語法 // // main.m // oc基本語法 // // Created by lanou on...
    GOT_HODOR閱讀 443評論 0 0
  • 一:在ViewController中實例化MLPickerScrollView完成代理<MLPickerScrol...
    歐大帥Allen閱讀 6,842評論 1 9
  • 在iOS中隨處都可以看到絢麗的動畫效果,實現(xiàn)這些動畫的過程并不復雜,今天將帶大家一窺iOS動畫全貌。在這里你可以看...
    F麥子閱讀 5,141評論 5 13
  • 睡覺前,看到朋友圈里發(fā)的一個標題為《霧霾侵入人體的全過程》的動畫短視頻。我突然萌發(fā)了一個念頭,就拿這個動畫視...
    六棱雪閱讀 376評論 0 5