HXPhotoLimitView.m 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. //
  2. // HXPhotoLimitView.m
  3. // HXPhotoPickerExample
  4. //
  5. // Created by Slience on 2021/9/6.
  6. // Copyright © 2021 洪欣. All rights reserved.
  7. //
  8. #import "HXPhotoLimitView.h"
  9. #import "NSBundle+HXPhotoPicker.h"
  10. #import "UIColor+HXExtension.h"
  11. #import "UIImage+HXExtension.h"
  12. #import "UIView+HXExtension.h"
  13. #import "UILabel+HXExtension.h"
  14. #import "HXPhotoTools.h"
  15. @interface HXPhotoLimitView()
  16. @property (strong, nonatomic) UIVisualEffectView *bgView;
  17. @property (strong, nonatomic) UILabel *textLb;
  18. @property (strong, nonatomic) UIButton *settingButton;
  19. @property (strong, nonatomic) UIButton *closeButton;
  20. @end
  21. @implementation HXPhotoLimitView
  22. - (instancetype)initWithFrame:(CGRect)frame {
  23. self = [super initWithFrame:frame];
  24. if (self) {
  25. [self addSubview:self.bgView];
  26. [self addSubview:self.textLb];
  27. [self addSubview:self.settingButton];
  28. [self addSubview:self.closeButton];
  29. self.layer.cornerRadius = 7;
  30. self.layer.masksToBounds = YES;
  31. }
  32. return self;
  33. }
  34. - (void)setTextColor:(UIColor *)color {
  35. self.textLb.textColor = color;
  36. }
  37. - (void)setSettingColor:(UIColor *)color {
  38. [self.settingButton setTitleColor:color forState:UIControlStateNormal];
  39. }
  40. - (void)setCloseColor:(UIColor *)color {
  41. self.closeButton.imageView.tintColor = color;
  42. self.closeButton.tintColor = color;
  43. }
  44. - (void)setBlurEffectStyle:(UIBlurEffectStyle)style {
  45. UIBlurEffect *effect = [UIBlurEffect effectWithStyle:style];
  46. self.bgView.effect = effect;
  47. }
  48. - (void)layoutSubviews {
  49. [super layoutSubviews];
  50. self.bgView.frame = self.bounds;
  51. CGFloat settingTextWidth = [self.settingButton.titleLabel hx_getTextWidth];
  52. self.textLb.frame = CGRectMake(10, 0, self.hx_w - settingTextWidth - 35, self.hx_h);
  53. CGFloat textWidth = self.textLb.hx_getTextWidth;
  54. if (self.textLb.hx_w > textWidth) {
  55. self.textLb.hx_w = textWidth;
  56. }
  57. CGFloat settingX = CGRectGetMaxX(self.textLb.frame) + 5;
  58. self.settingButton.frame = CGRectMake(settingX, 0, settingTextWidth, self.hx_h);
  59. self.closeButton.hx_size = CGSizeMake(18, 18);
  60. self.closeButton.hx_x = self.hx_w - self.closeButton.hx_w;
  61. self.closeButton.hx_y = 0;
  62. }
  63. - (UIVisualEffectView *)bgView {
  64. if (!_bgView) {
  65. UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
  66. _bgView = [[UIVisualEffectView alloc] initWithEffect:effect];
  67. }
  68. return _bgView;
  69. }
  70. - (UILabel *)textLb {
  71. if (!_textLb) {
  72. _textLb = [[UILabel alloc] init];
  73. _textLb.text = [NSBundle hx_localizedStringForKey:@"仅可访问部分照片,建议开启「所有照片」"];
  74. _textLb.font = [UIFont systemFontOfSize:14];
  75. _textLb.textColor = [UIColor hx_colorWithHexStr:@"#999999"];
  76. _textLb.numberOfLines = 0;
  77. _textLb.adjustsFontSizeToFitWidth = YES;
  78. }
  79. return _textLb;
  80. }
  81. - (UIButton *)settingButton {
  82. if (!_settingButton) {
  83. _settingButton = [UIButton buttonWithType:UIButtonTypeSystem];
  84. [_settingButton setTitle:[NSBundle hx_localizedStringForKey:@"去设置"] forState:UIControlStateNormal];
  85. [_settingButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  86. _settingButton.titleLabel.font = [UIFont systemFontOfSize:14];
  87. [_settingButton addTarget:self action:@selector(didSettingButtonClick) forControlEvents:UIControlEventTouchUpInside];
  88. _settingButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  89. }
  90. return _settingButton;
  91. }
  92. - (void)didSettingButtonClick {
  93. [HXPhotoTools openSetting];
  94. }
  95. - (UIButton *)closeButton {
  96. if (!_closeButton) {
  97. _closeButton = [UIButton buttonWithType:UIButtonTypeSystem];
  98. [_closeButton setImage:[UIImage hx_imageNamed:@"hx_compose_delete"] forState:UIControlStateNormal];
  99. [_closeButton addTarget:self action:@selector(didCloseButtonClick) forControlEvents:UIControlEventTouchUpInside];
  100. _closeButton.imageView.tintColor = [UIColor whiteColor];
  101. _closeButton.tintColor = [UIColor whiteColor];
  102. }
  103. return _closeButton;
  104. }
  105. - (void)didCloseButtonClick {
  106. [UIView animateWithDuration:0.25 animations:^{
  107. self.alpha = 0;
  108. } completion:^(BOOL finished) {
  109. [self removeFromSuperview];
  110. }];
  111. }
  112. @end