《省钱达人》与《猎豆优选》UI相同版。域名tbk

DRTimeLineChannelCell.m 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. //
  2. // DRTimeLineChannelCell.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2019/1/3.
  6. // Copyright © 2019年 kuxuan. All rights reserved.
  7. //
  8. #import "DRTimeLineChannelCell.h"
  9. #import "DRLoginViewController.h"
  10. @interface DRTimeLineChannelCell ()
  11. @property (nonatomic, strong) UIImageView *iconView;
  12. @property (nonatomic, strong) UILabel *title;
  13. @property (nonatomic, strong) UIButton *signBtn;
  14. @end
  15. @implementation DRTimeLineChannelCell
  16. - (instancetype)initWithFrame:(CGRect)frame
  17. {
  18. self = [super initWithFrame:frame];
  19. if (self) {
  20. [self initSubViews];
  21. }
  22. return self;
  23. }
  24. - (void)initSubViews {
  25. [self.contentView addSubview:self.iconView];
  26. [self.contentView addSubview:self.title];
  27. [self.contentView addSubview:self.signBtn];
  28. [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
  29. make.top.mas_equalTo(10);
  30. make.centerX.mas_equalTo(self.mas_centerX);
  31. make.width.height.mas_equalTo(48);
  32. }];
  33. [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
  34. make.top.mas_equalTo(self.iconView.mas_bottom).mas_offset(10);
  35. make.centerX.mas_equalTo(self.iconView.mas_centerX);
  36. make.width.mas_equalTo(80);
  37. }];
  38. [self.signBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  39. make.top.mas_equalTo(self.title.mas_bottom).mas_offset(13);
  40. make.width.mas_equalTo(50);
  41. make.height.mas_equalTo(18);
  42. make.centerX.mas_equalTo(self.title.mas_centerX);
  43. }];
  44. }
  45. - (void)setModel:(DRTimeLineChannelModel *)model {
  46. _model = model;
  47. [self.iconView sd_setFadeImageWithURL:[NSURL URLWithString:model.img] placeholderImage:nil options:0 progress:nil completed:nil];
  48. self.title.text = model.title;
  49. self.signBtn.selected = model.status.boolValue;
  50. }
  51. - (void)signAction:(UIButton *)sender {
  52. if (![AccountTool isLogin]) {
  53. DRLoginViewController *login = [[DRLoginViewController alloc] init];
  54. [[self currentViewController] presentViewController:login animated:YES completion:nil];
  55. return;
  56. }
  57. sender.enabled = NO;
  58. NSString *url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/subscribeLabel",BaseURL];
  59. NSNumber *status = sender.selected?@(0):@(1);
  60. NSDictionary *para = @{@"label_id":self.model.Id,@"status":status};
  61. [DRHttp post:url params:para success:^(id json) {
  62. NSNumber *flag = json[@"flag"];
  63. if (flag.boolValue) {
  64. sender.selected = !sender.selected;
  65. }
  66. [XHToast showCenterWithText:json[@"msg"]];
  67. sender.enabled = YES;
  68. } failure:^(NSError *error) {
  69. sender.enabled = YES;
  70. }];
  71. [MobClick event:OptimizingCircleLabelClick label:self.model.title];
  72. }
  73. #pragma mark -----
  74. - (UIImageView *)iconView {
  75. if (!_iconView) {
  76. _iconView = [[UIImageView alloc] init];
  77. _iconView.layer.cornerRadius = 24;
  78. _iconView.layer.masksToBounds = YES;
  79. _iconView.backgroundColor = [UIColor yhGrayColor];
  80. }
  81. return _iconView;
  82. }
  83. - (UILabel *)title {
  84. if (!_title) {
  85. _title = [[UILabel alloc] init];
  86. _title.font = [UIFont systemFontOfSize:14];
  87. _title.textColor = [UIColor YHColorWithHex:0x4B4B4B];
  88. _title.textAlignment = NSTextAlignmentCenter;
  89. }
  90. return _title;
  91. }
  92. - (UIButton *)signBtn {
  93. if (!_signBtn) {
  94. _signBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  95. [_signBtn setImage:[UIImage imageNamed:@"sign_n"] forState:UIControlStateNormal];
  96. [_signBtn setImage:[UIImage imageNamed:@"signed"] forState:UIControlStateSelected];
  97. [_signBtn addTarget:self action:@selector(signAction:) forControlEvents:UIControlEventTouchUpInside];
  98. }
  99. return _signBtn;
  100. }
  101. - (UIViewController *)currentViewController{
  102. UIViewController * currVC = nil;
  103. UIWindow *window = [UIApplication sharedApplication].delegate.window;
  104. UIViewController * Rootvc = window.rootViewController;
  105. do {
  106. if ([Rootvc isKindOfClass:[UINavigationController class]]) {
  107. UINavigationController * nav = (UINavigationController *)Rootvc;
  108. UIViewController * v = [nav.viewControllers lastObject];
  109. currVC = v;
  110. Rootvc = v.presentedViewController;
  111. continue;
  112. }else if([Rootvc isKindOfClass:[UITabBarController class]]){
  113. UITabBarController * tabVC = (UITabBarController *)Rootvc;
  114. currVC = tabVC;
  115. Rootvc = [tabVC.viewControllers objectAtIndex:tabVC.selectedIndex];
  116. continue;
  117. }
  118. } while (Rootvc!=nil);
  119. return currVC;
  120. }
  121. @end