1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- //
- // RandomAD.m
- // jiaPei
- //
- // Created by apple on 16/5/3.
- // Copyright © 2016年 JCZ. All rights reserved.
- //
- #import "RandomAD.h"
- #import "ADLinkVC.h"
- @implementation RandomAD
- -(id)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self) {
-
- _imageView = [[UIImageView alloc] initWithFrame:frame];
- _imageView.contentMode = UIViewContentModeScaleAspectFill;
- [_imageView setClipsToBounds:YES];
- [self addSubview:_imageView];
-
- _backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- _backBtn.frame = CGRectMake(frame.size.width - 40, 5, 30, 30);
- [_backBtn setImage:[[UIImage imageNamed:@"community6"] tint:[UIColor redColor]] forState:UIControlStateNormal];
- [_backBtn borderColor:[UIColor redColor] width:2 cornorRadios:15];
- [self addSubview:_backBtn];
-
- //[self bringSubviewToFront:_backBtn];
- }
- return self;
- }
- - (void)setImgArray:(NSArray *)imgArray{
-
- _imgArray = imgArray;
-
- if (imgArray.count < 1) {
-
- [_imageView setImage:[UIImage imageNamed:@"subject_main_banner.jpg"]];
- }else{
-
- //NSLog(@"----?>%d",(int)_rendomIndex);
- NSDictionary *dic = imgArray[_rendomIndex];
-
- NSString *path = dic[@"IMG"];
- if (path && ![path hasPrefix:@"http"]){
- path = [imgPreFix stringByAppendingString:path];
- }
-
- [_imageView sd_setImageWithURL:[NSURL URLWithString:path] placeholderImage:[UIImage imageNamed:@"subject_main_banner.jpg"]];
-
- //把手势添加到指定视图上
- [_imageView setUserInteractionEnabled:YES];
- UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(skipToADLink:)];
- [_imageView addGestureRecognizer:tapGesture];
-
- _imageView.tag = _rendomIndex;
- }
- }
- //程序内跳转
- -(void)skipToADLink:(UITapGestureRecognizer *)gesture
- {
- //1是程序内 2是程序外
- NSDictionary *dic = _imgArray[_rendomIndex];
-
- //NSLog(@"--->%@",_imgArray);
-
- NSString *skipType = dic[@"OPENTYPE"];
-
- if ([skipType isEqualToString:@"1"]) {
-
- ADLinkVC *ad = [[ADLinkVC alloc] init];
- ad.title = dic[@"TITLE"];
- ad.urlString = dic[@"URL"];
- if (ad.urlString && ad.urlString.length != 0) {
- [_supVC navPushHideTabbarToVC:ad];
- }
-
- }else{
-
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:dic[@"URL"]]];
- }
- }
- @end
|