説明なし

FKProBannerCell.m 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. // FKProBannerCell.m
  3. // FirstLink
  4. //
  5. // Created by jack on 16/8/12.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKProBannerCell.h"
  9. #import "FKProDetailViewModel.h"
  10. @interface FKProBannerCell () <DPBannerViewDelegate>
  11. @end
  12. @implementation FKProBannerCell
  13. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  14. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  15. if (self) {
  16. [self addAllSubViews];
  17. }
  18. return self;
  19. }
  20. - (void)addAllSubViews {
  21. [self.contentView addSubview:self.banerView];
  22. [self.contentView addSubview:self.pageControl];
  23. [self.contentView addSubview:self.goToDetailBtn];
  24. [self.contentView addSubview:self.pageControl];
  25. [self.pageControl mas_makeConstraints:^(MASConstraintMaker *make) {
  26. make.left.equalTo(self.banerView);
  27. make.right.equalTo(self.banerView);
  28. make.bottom.equalTo(self.banerView).offset(-8);
  29. make.height.mas_equalTo(20);
  30. }];
  31. [self.goToDetailBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  32. make.right.equalTo(self.contentView).offset(- 10);
  33. make.bottom.equalTo(self.contentView).offset(- 30);
  34. make.width.height.mas_equalTo(40);
  35. }];
  36. [self.pageControl mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.left.equalTo(self.banerView);
  38. make.right.equalTo(self.banerView);
  39. make.bottom.equalTo(self.banerView).offset(-8);
  40. make.height.mas_equalTo(20);
  41. }];
  42. }
  43. - (void)fk_configWithViewModel:(id)viewModel indexPath:(NSIndexPath *)indexPath{
  44. if ([viewModel isKindOfClass:[FKProDetailViewModel class]]) {
  45. FKProDetailViewModel *detailModel = (FKProDetailViewModel *)viewModel;
  46. self.banerView.duration = 0.0f;
  47. self.banerView.imageUrls = detailModel.specPicArray;
  48. self.pageControl.numberOfPages = detailModel.specPicArray.count;
  49. }
  50. }
  51. - (void)bannerView:(DPBannerView *)bannerView didSelectedAtIndex:(NSInteger)index{
  52. if (self.clickAction) {
  53. self.clickAction(index, self);
  54. }
  55. }
  56. - (void)bannerView:(DPBannerView *)bannerView didShowAtIndex:(NSInteger)index{
  57. self.pageControl.currentPage = index;
  58. }
  59. #pragma mark - Property
  60. - (DPBannerView *)banerView{
  61. if (_banerView == nil) {
  62. _banerView = [[DPBannerView alloc]initWithFrame:CGRectMake(0, 0, UISCREENWIDTH, UISCREENWIDTH)];
  63. // _banerView.backgroundColor = UIColorFromRGB(0xeeeeee);
  64. _banerView.duration = 0.0f;
  65. _banerView.delegate = self;
  66. _banerView.defalutContentModel = UIViewContentModeScaleAspectFit;
  67. }
  68. return _banerView;
  69. }
  70. - (UIPageControl*)pageControl {
  71. if (!_pageControl) {
  72. _pageControl = [[UIPageControl alloc]init];
  73. _pageControl.currentPage = 0;
  74. _pageControl.hidesForSinglePage = YES;
  75. _pageControl.pageIndicatorTintColor = [UIColorFromRGB(0xaaaaaa) colorWithAlphaComponent:0.3];
  76. _pageControl.currentPageIndicatorTintColor = [UIColorFromRGB(0xaaaaaa) colorWithAlphaComponent:0.7];
  77. }
  78. return _pageControl;
  79. }
  80. - (UIButton *)goToDetailBtn{
  81. if (_goToDetailBtn == nil) {
  82. _goToDetailBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  83. [_goToDetailBtn setTitle:@"商品\n详情" forState:UIControlStateNormal];
  84. [_goToDetailBtn setTitleColor:UIColorFromRGB(0x333333) forState:UIControlStateNormal];
  85. _goToDetailBtn.titleLabel.font = [UIFont systemFontOfSize:10];
  86. _goToDetailBtn.titleLabel.numberOfLines = 2;
  87. _goToDetailBtn.backgroundColor = [UIColorFromRGB(0x000000) colorWithAlphaComponent:0.1];
  88. _goToDetailBtn.layer.cornerRadius = 20.0f;
  89. _goToDetailBtn.layer.masksToBounds = YES;
  90. }
  91. return _goToDetailBtn;
  92. }
  93. #pragma mark - Helper
  94. + (CGFloat)height {
  95. return UISCREENWIDTH;
  96. }
  97. @end