RQSimulationTestTopicsHeaderView.m 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // RQSimulationTestTopicsHeaderView.m
  3. // SDJK
  4. //
  5. // Created by 张嵘 on 2021/8/10.
  6. //
  7. #import "RQSimulationTestTopicsHeaderView.h"
  8. #define PI 3.14159265358979323846
  9. @interface RQSimulationTestTopicsHeaderView ()
  10. @property (weak, nonatomic) IBOutlet UIButton *backBtn;
  11. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *titleLabelHeight;
  12. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *titleLabelToTopConst;
  13. @property (weak, nonatomic) IBOutlet UIImageView *headerImageView;
  14. @property (weak, nonatomic) IBOutlet UILabel *nicknameLabel;
  15. @end
  16. @implementation RQSimulationTestTopicsHeaderView
  17. + (instancetype)simulationTestTopicsHeaderView {
  18. return [super rq_viewFromXib];
  19. }
  20. - (void)awakeFromNib {
  21. [super awakeFromNib];
  22. CGFloat radius = RQ_SCREEN_WIDTH;
  23. //特别注意:贝塞尔曲线的radius必须为self高度的四分之一,CAShapeLayer的线宽必须为self高度的二分之一
  24. UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(RQ_SCREEN_WIDTH / 2.f, RQSimulationTestTopicsViewHeight - 20 + RQ_APPLICATION_STATUS_BAR_HEIGHT - radius) radius:radius / 2 startAngle:-PI/2 endAngle:PI *3 / 2 clockwise:YES];
  25. CAShapeLayer *maskLayer = [CAShapeLayer layer];
  26. maskLayer.path = path.CGPath;
  27. maskLayer.fillColor = [UIColor clearColor].CGColor;
  28. maskLayer.strokeColor = RQ_MAIN_BACKGROUNDCOLOR.CGColor;
  29. maskLayer.lineWidth = radius;
  30. //等于半径的2倍,以圆的边缘为中心,向圆内部伸展一个半径,向外伸展一个半径,所以看上去以为圆的半径是self高度的一半。
  31. self.layer.mask = maskLayer;
  32. [self bringSubviewToFront:_backBtn];
  33. // [self.layer addSublayer:[UIColor setGradualChangingColor:self fromColor:@"#498EF5" toColor:@"#4DA8E6"]];
  34. self.backgroundColor = [UIColor rq_colorGradientChangeWithSize:CGSizeMake(self.bounds.size.width, self.bounds.size.height - 20 + RQ_APPLICATION_STATUS_BAR_HEIGHT) direction:RQGradientChangeDirectionVertical startColor:[UIColor colorWithHexString:@"#498EF5"] endColor:[UIColor colorWithHexString:@"#4DA8E6"]];
  35. _titleLabelHeight.constant = RQ_APPLICATION_NAV_BAR_HEIGHT;
  36. _titleLabelToTopConst.constant = RQ_APPLICATION_STATUS_BAR_HEIGHT;
  37. _nicknameLabel.text = RQ_USER_MANAGER.nickName;
  38. [_headerImageView yy_setImageWithURL:[NSURL URLWithString:RQ_USER_MANAGER.headImage] placeholder:RQWebAvatarImagePlaceholder() options:RQWebImageOptionAutomatic completion:^(UIImage * _Nullable image, NSURL * _Nonnull url, YYWebImageFromType from, YYWebImageStage stage, NSError * _Nullable error) {
  39. if(image) {
  40. image = [image scaledToSize:CGSizeMake(54, 54)];
  41. image = [image qmui_imageWithClippedCornerRadius:27];
  42. _headerImageView.image = image;
  43. }
  44. }];
  45. }
  46. @end