RandomAD.m 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // RandomAD.m
  3. // jiaPei
  4. //
  5. // Created by apple on 16/5/3.
  6. // Copyright © 2016年 JCZ. All rights reserved.
  7. //
  8. #import "RandomAD.h"
  9. #import "ADLinkVC.h"
  10. @implementation RandomAD
  11. -(id)initWithFrame:(CGRect)frame
  12. {
  13. self = [super initWithFrame:frame];
  14. if (self) {
  15. _imageView = [[UIImageView alloc] initWithFrame:frame];
  16. _imageView.contentMode = UIViewContentModeScaleAspectFill;
  17. [_imageView setClipsToBounds:YES];
  18. [self addSubview:_imageView];
  19. _backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  20. _backBtn.frame = CGRectMake(frame.size.width - 40, 5, 30, 30);
  21. [_backBtn setImage:[[UIImage imageNamed:@"community6"] tint:[UIColor redColor]] forState:UIControlStateNormal];
  22. [_backBtn borderColor:[UIColor redColor] width:2 cornorRadios:15];
  23. [self addSubview:_backBtn];
  24. //[self bringSubviewToFront:_backBtn];
  25. }
  26. return self;
  27. }
  28. - (void)setImgArray:(NSArray *)imgArray{
  29. _imgArray = imgArray;
  30. if (imgArray.count < 1) {
  31. [_imageView setImage:[UIImage imageNamed:@"subject_main_banner.jpg"]];
  32. }else{
  33. //NSLog(@"----?>%d",(int)_rendomIndex);
  34. NSDictionary *dic = imgArray[_rendomIndex];
  35. NSString *path = dic[@"IMG"];
  36. if (path && ![path hasPrefix:@"http"]){
  37. path = [imgPreFix stringByAppendingString:path];
  38. }
  39. [_imageView sd_setImageWithURL:[NSURL URLWithString:path] placeholderImage:[UIImage imageNamed:@"subject_main_banner.jpg"]];
  40. //把手势添加到指定视图上
  41. [_imageView setUserInteractionEnabled:YES];
  42. UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(skipToADLink:)];
  43. [_imageView addGestureRecognizer:tapGesture];
  44. _imageView.tag = _rendomIndex;
  45. }
  46. }
  47. //程序内跳转
  48. -(void)skipToADLink:(UITapGestureRecognizer *)gesture
  49. {
  50. //1是程序内 2是程序外
  51. NSDictionary *dic = _imgArray[_rendomIndex];
  52. //NSLog(@"--->%@",_imgArray);
  53. NSString *skipType = dic[@"OPENTYPE"];
  54. if ([skipType isEqualToString:@"1"]) {
  55. ADLinkVC *ad = [[ADLinkVC alloc] init];
  56. ad.title = dic[@"TITLE"];
  57. ad.urlString = dic[@"URL"];
  58. if (ad.urlString && ad.urlString.length != 0) {
  59. [_supVC navPushHideTabbarToVC:ad];
  60. }
  61. }else{
  62. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:dic[@"URL"]]];
  63. }
  64. }
  65. @end