GiftSubView.m 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. //
  2. // GiftSubView.m
  3. // BuguLive
  4. //
  5. // Created by xfg on 16/5/20.
  6. // Copyright © 2016年 xfg. All rights reserved.
  7. //
  8. #import "GiftSubView.h"
  9. #define kLabelHeight 15
  10. #define kImgViewY kHomeCateViewHeight-kLabelHeight-kImgViewWidth
  11. @implementation GiftSubView
  12. - (id)initWithFrame:(CGRect)frame
  13. {
  14. self = [super initWithFrame:frame];
  15. if (self)
  16. {
  17. self.backgroundColor = [UIColor clearColor];
  18. // self.layer.borderWidth = 0.5;
  19. // self.layer.borderColor = [kWhiteColor colorWithAlphaComponent:0.1].CGColor;
  20. // CAShapeLayer *dottedLineBorder = [[CAShapeLayer alloc] init];
  21. // dottedLineBorder.frame = CGRectMake(0, 0, self.width, self.height);
  22. // [dottedLineBorder setLineWidth:0.5];
  23. // [dottedLineBorder setStrokeColor:[kWhiteColor colorWithAlphaComponent:0.1].CGColor];
  24. // [dottedLineBorder setFillColor:kClearColor.CGColor];
  25. // UIBezierPath *path = [UIBezierPath bezierPathWithRect:dottedLineBorder.frame];
  26. // dottedLineBorder.path = path.CGPath;
  27. // [self.layer addSublayer:dottedLineBorder];
  28. CGFloat subViewW = frame.size.width;
  29. CGFloat subViewH = frame.size.height;
  30. CGFloat marginY = kRealValue(15);
  31. _diamondsImgView = [[UIImageView alloc]initWithFrame:CGRectMake(subViewW*0.4, subViewH-kDefaultMargin-10 - marginY, 11, 11)];
  32. _diamondsImgView.contentMode = UIViewContentModeScaleAspectFit;
  33. [_diamondsImgView setImage:[UIImage imageNamed:@"com_diamond_1"]];
  34. [self addSubview:_diamondsImgView];
  35. _diamondsLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(_diamondsImgView.frame)+3, CGRectGetMinY(_diamondsImgView.frame)-3, subViewW*0.7-6, kLabelHeight)];
  36. _diamondsLabel.font = [UIFont systemFontOfSize:12.0];
  37. _diamondsLabel.textColor = kWhiteColor;
  38. [self addSubview:_diamondsLabel];
  39. _txtLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, CGRectGetMinY(_diamondsImgView.frame)-kDefaultMargin - marginY, subViewW-10, kLabelHeight)];
  40. _txtLabel.font = [UIFont systemFontOfSize:13.0];
  41. _txtLabel.textAlignment = NSTextAlignmentCenter;
  42. _txtLabel.textColor = kWhiteColor;
  43. [self addSubview:_txtLabel];
  44. CGFloat min = MIN(subViewW, subViewH-kLabelHeight*2)*0.7;
  45. CGFloat imgViewWAndH = min - kRealValue(20);
  46. CGFloat widthMargin = 5;
  47. _imgView = [[FLAnimatedImageView alloc]initWithFrame:CGRectMake((subViewW-imgViewWAndH)/2- widthMargin /2, (subViewH-imgViewWAndH-kLabelHeight*2)/2 - marginY, imgViewWAndH + widthMargin, imgViewWAndH)];
  48. _imgView.contentMode = UIViewContentModeScaleAspectFit;
  49. [self addSubview:_imgView];
  50. //连
  51. _continueImgView = [[UIImageView alloc]initWithFrame:CGRectMake(subViewW-20, 5, 15, 15)];
  52. _continueImgView.contentMode = UIViewContentModeScaleAspectFit;
  53. _continueImgView.hidden = YES;
  54. [_continueImgView setImage:[UIImage imageNamed:@"lr_gift_list_continue"]];
  55. [self addSubview:_continueImgView];
  56. //是否是幸运礼物
  57. _luckBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  58. _luckBtn.frame =CGRectMake(self.width - kRealValue(39), 6, kRealValue(35), kRealValue(15));
  59. [_luckBtn setTitle:ASLocalizedString(@"动效") forState:UIControlStateNormal];
  60. [_luckBtn setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
  61. _luckBtn.titleLabel.font = [UIFont systemFontOfSize:10];
  62. [_luckBtn setTitleColor:kWhiteColor forState:UIControlStateNormal];
  63. _luckBtn.hidden = YES;
  64. [self addSubview:_luckBtn];
  65. // _luckLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.width - kRealValue(39), 6, kRealValue(35), kRealValue(15))];
  66. //// _luckLabel.layer.borderColor = kRedColor.CGColor;
  67. // _luckLabel.clipsToBounds = YES;
  68. //// _luckLabel.layer.borderWidth = 1;
  69. // _luckLabel.font = [UIFont systemFontOfSize:12];
  70. // _luckLabel.text = ASLocalizedString(@"幸运");
  71. // _luckLabel.textAlignment = NSTextAlignmentCenter;
  72. // _luckLabel.textColor = kWhiteColor;
  73. // _luckLabel.layer.cornerRadius = kRealValue(15) / 2;
  74. // _luckLabel.backgroundColor = [UIColor colorWithHexString:@"#FF4081"];
  75. //// _luckLabel.hidden = YES;
  76. // [self addSubview:_luckLabel];
  77. //用来被点击的按钮
  78. _bottomBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  79. _bottomBtn.frame = CGRectMake(1 + widthMargin / 2, 1 + widthMargin / 2, subViewW-2 - widthMargin, subViewH-2 - widthMargin);
  80. _bottomBtn.backgroundColor = [UIColor clearColor];
  81. [_bottomBtn addTarget:self action:@selector(btnAction) forControlEvents:UIControlEventTouchUpInside];
  82. _bottomBtn.layer.borderWidth = 0.5;
  83. _bottomBtn.layer.cornerRadius = 5;
  84. _bottomBtn.layer.borderColor = [[UIColor colorWithHexString:@"#ffffff"] colorWithAlphaComponent:0.6].CGColor;
  85. [self addSubview:_bottomBtn];
  86. _luckyImgView = [UIImageView new];
  87. _luckyImgView.frame = CGRectMake(8, 8, 35, 15);
  88. _luckyImgView.image = [UIImage imageNamed:@"mg_gift_lucky"];
  89. _luckyImgView.hidden = YES;
  90. [self addSubview:_luckyImgView];
  91. }
  92. return self;
  93. }
  94. - (void)btnAction
  95. {
  96. CAKeyframeAnimation* animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];animation.duration = 0.8;// 动画时间
  97. NSMutableArray *values = [NSMutableArray array];[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];// 这三个数字,我只研究了前两个,所以最后一个数字我还是按照它原来写1.0;前两个是控制view的大小的;
  98. [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.25, 1.25, 1.0)]];
  99. [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
  100. animation.values = values;
  101. [self.imgView.layer addAnimation:animation forKey:nil];
  102. if (_delegate && [_delegate respondsToSelector:@selector(cateBtn:index_x:index_y:)])
  103. {
  104. [_delegate cateBtn:(int)self.tag index_x:self.index_x index_y:self.index_y];
  105. }
  106. }
  107. - (void)resetDiamondsFrame
  108. {
  109. if (![BGUtils isBlankString:_diamondsLabel.text])
  110. {
  111. CGSize titleSize = [_diamondsLabel.text boundingRectWithSize:CGSizeMake(100, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size;
  112. CGFloat tmpX = (self.frame.size.width-3-CGRectGetWidth(_diamondsImgView.frame)-titleSize.width)/2;
  113. _diamondsImgView.frame = CGRectMake(tmpX, CGRectGetMinY(_diamondsImgView.frame), CGRectGetWidth(_diamondsImgView.frame), CGRectGetHeight(_diamondsImgView.frame));
  114. _diamondsLabel.frame = CGRectMake(CGRectGetMaxX(_diamondsImgView.frame)+3, CGRectGetMinY(_diamondsLabel.frame), CGRectGetWidth(_diamondsLabel.frame), CGRectGetHeight(_diamondsLabel.frame));
  115. }
  116. }
  117. @end