previewLandscapeTopView.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //
  2. // previewLandscapeTopView.m
  3. // Private-X
  4. //
  5. // Created by xd h on 2024/7/10.
  6. //
  7. #import "previewLandscapeTopView.h"
  8. @interface previewLandscapeTopView ()
  9. @property(nonatomic,strong) UIButton*shareButton;
  10. @property(nonatomic,strong) UIButton*moreButton;
  11. @end
  12. @implementation previewLandscapeTopView
  13. - (id)initWithFrame:(CGRect)frame{
  14. self = [super initWithFrame:frame];
  15. self.backgroundColor = [UIColor hwColor:@"#000000" alpha:0.6];
  16. [self drawAnyView];
  17. return self;
  18. }
  19. - (void)drawAnyView{
  20. CGFloat curW = SCREEN_W;
  21. CGFloat curH = SCREEN_H;
  22. if(curW<curH){//横屏宽度最大
  23. curW = curH;
  24. }
  25. // gradient
  26. CAGradientLayer *gl = [CAGradientLayer layer];
  27. gl.frame = CGRectMake(0,0,curW,60);
  28. gl.startPoint = CGPointMake(0.5, 0);
  29. gl.endPoint = CGPointMake(0.5, 1);
  30. gl.colors = @[(__bridge id)[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1.0].CGColor, (__bridge id)[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.0].CGColor];
  31. gl.locations = @[@(0), @(1.0f)];
  32. //[self.layer addSublayer:gl];
  33. [self.layer insertSublayer:gl atIndex:0];
  34. _backButton = [[UIButton alloc] init];
  35. _backButton.tag = 1;
  36. [_backButton setImage:[UIImage imageNamed:@"icon_white_back"] forState:(UIControlStateNormal)];
  37. [_backButton addTarget:self
  38. action:@selector(didClickButtonFun:)
  39. forControlEvents:(UIControlEventTouchUpInside)];
  40. [self addSubview:_backButton];
  41. [_backButton mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.top.mas_equalTo(0);
  43. make.left.mas_equalTo(10);
  44. make.width.mas_equalTo(60);
  45. make.height.mas_equalTo(60);
  46. }];
  47. _moreButton = [[UIButton alloc] init];
  48. _moreButton.tag = 2;
  49. [_moreButton setImage:[UIImage imageNamed:@"nas_preview_more_white"] forState:(UIControlStateNormal)];
  50. [_moreButton addTarget:self
  51. action:@selector(didClickButtonFun:)
  52. forControlEvents:(UIControlEventTouchUpInside)];
  53. [self addSubview:_moreButton];
  54. [_moreButton mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.top.mas_equalTo(0);
  56. make.right.mas_equalTo(-10);
  57. make.width.mas_equalTo(60);
  58. make.height.mas_equalTo(60);
  59. }];
  60. _shareButton = [[UIButton alloc] init];
  61. _shareButton.tag = 3;
  62. [_shareButton setImage:[UIImage imageNamed:@"nas_preview_share_white"] forState:(UIControlStateNormal)];
  63. [_shareButton addTarget:self
  64. action:@selector(didClickButtonFun:)
  65. forControlEvents:(UIControlEventTouchUpInside)];
  66. [self addSubview:_shareButton];
  67. [_shareButton mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.top.mas_equalTo(0);
  69. make.right.equalTo(_moreButton.mas_left).offset(0);
  70. make.width.mas_equalTo(60);
  71. make.height.mas_equalTo(60);
  72. }];
  73. _titleLabel = [[UILabel alloc] init];
  74. [_titleLabel setTextColor:[UIColor whiteColor]];
  75. [_titleLabel setFont:[UIFont boldSystemFontOfSize:18.f]];
  76. _titleLabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
  77. [self addSubview:_titleLabel];
  78. [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  79. make.centerY.equalTo(self.mas_centerY);
  80. make.left.equalTo(_backButton.mas_right).offset(10);
  81. make.right.equalTo(_shareButton.mas_left).offset(-10);
  82. //make.height.mas_equalTo(25);
  83. }];
  84. }
  85. #pragma mark 按钮点击事件
  86. - (void)didClickButtonFun:(UIButton*)but
  87. {
  88. NSInteger tag = but.tag;
  89. if(_didClickButton){
  90. _didClickButton(tag);
  91. }
  92. }
  93. @end