KWMAdHeader.m 2.67 KB
Newer Older
houweibin committed
1 2 3 4 5 6 7 8 9
//
//  KWMAdHeader.m
//  iCemarose
//
//  Created by HouWeiBin on 2017/7/10.
//  Copyright © 2017年 kollway. All rights reserved.
//

#import "KWMAdHeader.h"
houweibin committed
10
#import "UIImageView+WebCache.h"
u  
lee committed
11
#import <SDCycleScrollView/SDCycleScrollView.h>
houweibin committed
12

houweibin committed
13

u  
lee committed
14
@interface KWMAdHeader()<SDCycleScrollViewDelegate>
houweibin committed
15

u  
lee committed
16
 @property (nonatomic,strong) SDCycleScrollView *focusView;
houweibin committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

@end

@implementation KWMAdHeader

+(NSString *)kwmTag{
    return @"KWMAdHeader";
}

- (id)init{
    if (self=[super init]){
        [self addView];
    }
    return self;
}

- (id)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self addView];
    }
    return self;
}

-(instancetype)initWithFrame:(CGRect)frame{
    if (self =[super initWithFrame:frame]) {
        [self addView];
    }
    return self;
}

-(void)addView{
u  
lee committed
49 50 51 52
//    self.bannerView = [[KWMBannerView alloc]initWithFrame:self.frame];
//    self.bannerView.delegate = self;
//    [self addSubview:self.bannerView];
    [self initFocusView];
houweibin committed
53 54 55
}


houweibin committed
56 57
-(void)setAdArray:(NSArray<KWMAdvertisement *> *)adArray{
    _adArray = adArray;
u  
lee committed
58 59 60 61
//    [self.bannerView reloadData];
    _focusView.imageURLStringsGroup = [adArray rx_mapWithBlock:^id(KWMAdvertisement *each) {
        return each.image;
    }];
houweibin committed
62
}
u  
lee committed
63 64 65 66 67
-(void)initFocusView {
    if (!_focusView) {
        _focusView = [[SDCycleScrollView alloc] init];
        _focusView.delegate = self;
        _focusView.translatesAutoresizingMaskIntoConstraints = NO;
lee committed
68
//        _focusView.frame = CGRectMake(0, 0, UI_SCREEN_WIDTH, 304 * UI_SCREEN_WIDTH / 414);
u  
lee committed
69 70 71 72
        _focusView.autoScrollTimeInterval = 3;
        _focusView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
        _focusView.pageDotImage = [UIImage imageNamed:@"ic_page_1"];
        _focusView.currentPageDotImage = [UIImage imageNamed:@"ic_page_2"];
lee committed
73
        _focusView.placeholderImage = [UIImage imageNamed:@"ad_home_header_placeholder"];
u  
lee committed
74 75 76 77 78
        _focusView.backgroundColor = [UIColor whiteColor];
        [self addSubview:_focusView];
        NSDictionary *views = @{ @"v": _focusView };
        [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[v]|" options:0 metrics:nil views:views]];
        [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[v]|" options:0 metrics:nil views:views]];
houweibin committed
79 80 81
    }
}

u  
lee committed
82 83
-(void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
    [self.delegate kwm_gotoWebView:self.adArray[index].url];
houweibin committed
84 85
}

u  
lee committed
86 87 88 89 90 91
//-(void)bannerView:(KWMBannerView *)bannerView onClickPage:(NSInteger)index{
//    KWMAdvertisement *ad = [self.adArray objectAtIndex:index];
//    if(self.delegate){
//        [self.delegate kwm_gotoWebView:ad.url];
//    }
//}
houweibin committed
92 93

@end