BogoOpenWardBottomView.m 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. //
  2. // BogoOpenWardBottomView.m
  3. // BuguLive
  4. //
  5. // Created by 宋晨光 on 2021/10/9.
  6. // Copyright © 2021 xfg. All rights reserved.
  7. //
  8. #import "BogoOpenWardBottomView.h"
  9. @implementation BogoOpenWardBottomView
  10. - (instancetype)initWithFrame:(CGRect)frame
  11. {
  12. self = [super initWithFrame:frame];
  13. if (self) {
  14. self.backgroundColor = [UIColor whiteColor];
  15. UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 1)];
  16. // 阴影颜色
  17. line.layer.shadowColor = [UIColor blackColor].CGColor;
  18. // 阴影偏移,默认(0, -3)
  19. line.layer.shadowOffset = CGSizeMake(0,0);
  20. // 阴影透明度,默认0
  21. line.layer.shadowOpacity = 0.3;
  22. // 阴影半径,默认3
  23. line.layer.shadowRadius = 0.2;
  24. line.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.3];
  25. line.hidden = YES;
  26. [self setUpView];
  27. [self addSubview:line];
  28. }
  29. return self;
  30. }
  31. -(void)setUpView{
  32. self.timeBtn.hidden = YES;
  33. [self addSubview:self.myDiamondL];
  34. [self addSubview:self.timeBtn];
  35. [self addSubview:self.openBtn];
  36. self.openBtn.frame = CGRectMake(kScreenW - kRealValue(100 + 12), 0, kRealValue(100), kRealValue(34));
  37. self.openBtn.centerY = self.height / 2;
  38. self.openBtn.layer.cornerRadius = kRealValue(34 / 2);
  39. self.openBtn.layer.masksToBounds = YES;
  40. }
  41. - (void)setIs_guartian:(NSString *)is_guartian{
  42. if (is_guartian.integerValue == 1) {
  43. self.timeBtn.hidden = NO;
  44. self.myDiamondL.frame = CGRectMake(kRealValue(12), 2, kScreenW * 0.6, self.height / 2);
  45. self.timeBtn.frame = CGRectMake(kRealValue(12), self.myDiamondL.bottom - 4, kScreenW * 0.6, self.height / 2);
  46. [self.openBtn setTitle:ASLocalizedString(@"续费守护") forState:UIControlStateNormal];
  47. }else{
  48. self.timeBtn.hidden = YES;
  49. self.myDiamondL.frame = CGRectMake(kRealValue(12), 0, kScreenW * 0.6, self.height);
  50. [self.openBtn setTitle:ASLocalizedString(@"开通守护") forState:UIControlStateNormal];
  51. }
  52. }
  53. - (void)setGuartian_time:(NSString *)guartian_time{
  54. if (guartian_time.length > 10) {
  55. guartian_time = [guartian_time substringToIndex:10];
  56. }
  57. [self.timeBtn setTitle:[NSString stringWithFormat:@"%@:%@",ASLocalizedString(@"到期时间"),guartian_time] forState:UIControlStateNormal];
  58. }
  59. - (void)setGuartian_icon:(NSString *)guartian_icon{
  60. // [self.timeBtn setImageWithURL:[NSURL URLWithString:guartian_icon] forState:UIControlStateNormal options:YYWebImageOptionUseNSURLCache];
  61. // WeakSelf
  62. // [self.timeBtn setImageWithURL:[NSURL URLWithString:guartian_icon] forState:UIControlStateNormal placeholder:nil options:0 completion:^(UIImage * _Nullable image, NSURL * _Nonnull url, YYWebImageFromType from, YYWebImageStage stage, NSError * _Nullable error) {
  63. // image = [weakSelf scaleImage:image scaleToSize:CGSizeMake(kRealValue(50), kRealValue(18))];
  64. // [weakSelf.timeBtn setImage:image forState:UIControlStateNormal];
  65. // }];
  66. WeakSelf
  67. [self.timeBtn sd_setImageWithURL:[NSURL URLWithString:guartian_icon] forState:UIControlStateNormal completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  68. image = [weakSelf scaleImage:image scaleToSize:CGSizeMake(kRealValue(50), kRealValue(18))];
  69. [weakSelf.timeBtn setImage:image forState:UIControlStateNormal];
  70. }];
  71. // [self.timeBtn sd_setImageWithURL:[NSURL URLWithString:guartian_icon] forState:UIControlStateNormal];
  72. }
  73. - (void)setDiamondStr:(NSString *)diamondStr{
  74. self.myDiamondL.text = [NSString stringWithFormat:@"%@:%@",ASLocalizedString(@"我的钻石"),diamondStr];
  75. }
  76. -(void)openBtnAction{
  77. if (self.clickOpenBtnBlock) {
  78. self.clickOpenBtnBlock(YES);
  79. }
  80. }
  81. -(QMUIButton *)timeBtn{
  82. if (!_timeBtn) {
  83. _timeBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
  84. [_timeBtn setTitle:ASLocalizedString(@"到期时间") forState:UIControlStateNormal];
  85. _timeBtn.titleLabel.font = [UIFont systemFontOfSize:12];
  86. [_timeBtn setTitleColor:[UIColor colorWithHexString:@"#AAAAAA"] forState:UIControlStateNormal];
  87. _timeBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  88. _timeBtn.imagePosition = QMUIButtonImagePositionLeft;
  89. _timeBtn.spacingBetweenImageAndTitle = 2;
  90. }
  91. return _timeBtn;
  92. }
  93. -(UILabel *)myDiamondL{
  94. if (!_myDiamondL) {
  95. _myDiamondL = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, kScreenW / 2, kRealValue(60))];
  96. _myDiamondL.font = [UIFont systemFontOfSize:14];
  97. _myDiamondL.textColor = [UIColor colorWithHexString:@"#666666"];
  98. _myDiamondL.textAlignment = NSTextAlignmentLeft;
  99. _myDiamondL.text = ASLocalizedString(@"我的钻石");
  100. }
  101. return _myDiamondL;
  102. }
  103. -(QMUIButton *)openBtn{
  104. if (!_openBtn) {
  105. QMUIButton *openBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
  106. [openBtn setTitleColor:kWhiteColor forState:UIControlStateNormal];
  107. [openBtn setBackgroundImage:[UIImage imageNamed:@"lr_btn_ward_bg"] forState:UIControlStateNormal];
  108. [openBtn.titleLabel setFont:[UIFont systemFontOfSize:15]];
  109. [openBtn addTarget:self action:@selector(openBtnAction) forControlEvents:UIControlEventTouchUpInside];
  110. openBtn.layer.cornerRadius = 20;
  111. openBtn.clipsToBounds = YES;
  112. _openBtn = openBtn;
  113. }
  114. return _openBtn;
  115. }
  116. - (UIImage*)scaleImage:(UIImage *)image scaleToSize:(CGSize)size{
  117. // UIGraphicsBeginImageContext(size);
  118. UIGraphicsBeginImageContextWithOptions(size, NO, [UIScreen mainScreen].scale);
  119. [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
  120. UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
  121. UIGraphicsEndImageContext();
  122. return scaledImage;
  123. }
  124. @end