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

//
// 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)換成相應(yīng)的類
    //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)系作者
  • 序言:七十年代末至非,一起剝皮案震驚了整個濱河市粱锐,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌烛愧,老刑警劉巖除嘹,帶你破解...
    沈念sama閱讀 221,635評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件蚊伞,死亡現(xiàn)場離奇詭異定嗓,居然都是意外死亡裸影,警方通過查閱死者的電腦和手機勒庄,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,543評論 3 399
  • 文/潘曉璐 我一進店門串前,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人实蔽,你說我怎么就攤上這事荡碾。” “怎么了局装?”我有些...
    開封第一講書人閱讀 168,083評論 0 360
  • 文/不壞的土叔 我叫張陵坛吁,是天一觀的道長劳殖。 經(jīng)常有香客問我,道長拨脉,這世上最難降的妖魔是什么哆姻? 我笑而不...
    開封第一講書人閱讀 59,640評論 1 296
  • 正文 為了忘掉前任,我火速辦了婚禮玫膀,結(jié)果婚禮上矛缨,老公的妹妹穿的比我還像新娘。我一直安慰自己帖旨,他們只是感情好箕昭,可當(dāng)我...
    茶點故事閱讀 68,640評論 6 397
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著解阅,像睡著了一般落竹。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上货抄,一...
    開封第一講書人閱讀 52,262評論 1 308
  • 那天述召,我揣著相機與錄音,去河邊找鬼蟹地。 笑死积暖,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的锈津。 我是一名探鬼主播呀酸,決...
    沈念sama閱讀 40,833評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼凉蜂,長吁一口氣:“原來是場噩夢啊……” “哼琼梆!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起窿吩,我...
    開封第一講書人閱讀 39,736評論 0 276
  • 序言:老撾萬榮一對情侶失蹤茎杂,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后纫雁,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體煌往,經(jīng)...
    沈念sama閱讀 46,280評論 1 319
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,369評論 3 340
  • 正文 我和宋清朗相戀三年轧邪,在試婚紗的時候發(fā)現(xiàn)自己被綠了刽脖。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,503評論 1 352
  • 序言:一個原本活蹦亂跳的男人離奇死亡忌愚,死狀恐怖曲管,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情硕糊,我是刑警寧澤院水,帶...
    沈念sama閱讀 36,185評論 5 350
  • 正文 年R本政府宣布腊徙,位于F島的核電站,受9級特大地震影響檬某,放射性物質(zhì)發(fā)生泄漏撬腾。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,870評論 3 333
  • 文/蒙蒙 一恢恼、第九天 我趴在偏房一處隱蔽的房頂上張望民傻。 院中可真熱鬧,春花似錦厅瞎、人聲如沸饰潜。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,340評論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽彭雾。三九已至,卻和暖如春锁保,著一層夾襖步出監(jiān)牢的瞬間薯酝,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,460評論 1 272
  • 我被黑心中介騙來泰國打工爽柒, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留吴菠,地道東北人。 一個月前我還...
    沈念sama閱讀 48,909評論 3 376
  • 正文 我出身青樓浩村,卻偏偏與公主長得像做葵,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子心墅,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,512評論 2 359

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

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