FUHeadReusableView.m 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //
  2. // FUHeadReusableView.m
  3. // FUAlgorithmDemo
  4. //
  5. // Created by 孙慕 on 2020/5/21.
  6. // Copyright © 2020 孙慕. All rights reserved.
  7. //
  8. #import "FUHeadReusableView.h"
  9. @implementation FUHeadReusableView
  10. - (id)initWithFrame:(CGRect)frame
  11. {
  12. self = [super initWithFrame:frame];
  13. if (self)
  14. {
  15. int h = frame.size.height;
  16. int y = (h - 13)/2;
  17. UIView *view = [[UIView alloc] init];
  18. view.frame = CGRectMake(20,y,4,13);
  19. CAGradientLayer *gl = [CAGradientLayer layer];
  20. gl.frame = CGRectMake(20,y,4,13);
  21. gl.startPoint = CGPointMake(0, 0);
  22. gl.endPoint = CGPointMake(1, 1);
  23. gl.colors = @[(__bridge id)[UIColor colorWithRed:246/255.0 green:97/255.0 blue:255/255.0 alpha:1.0].CGColor,(__bridge id)[UIColor colorWithRed:119/255.0 green:85/255.0 blue:252/255.0 alpha:1.0].CGColor];
  24. gl.locations = @[@(0.0),@(1.0f)];
  25. gl.cornerRadius = 2;
  26. [self.layer addSublayer:gl];
  27. view.layer.cornerRadius = 2;
  28. _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20+4+8, (h -32)/2, 150, 32)];
  29. _titleLabel.textAlignment = NSTextAlignmentLeft;
  30. _titleLabel.textColor = [UIColor whiteColor];
  31. _titleLabel.font = [UIFont systemFontOfSize:15];
  32. [self addSubview:_titleLabel];
  33. }
  34. return self;
  35. }
  36. @end