CTAssetsPickerAccessDeniedView.m 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. MIT License (MIT)
  3. Copyright (c) 2015 Clement CN Tsang
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. */
  20. #import <PureLayout/PureLayout.h>
  21. #import "CTAssetsPickerDefines.h"
  22. #import "CTAssetsPickerAccessDeniedView.h"
  23. #import "NSBundle+CTAssetsPickerController.h"
  24. #import "UIImage+CTAssetsPickerController.h"
  25. @interface CTAssetsPickerAccessDeniedView ()
  26. @property (nonatomic, strong) UIImageView *padlock;
  27. @property (nonatomic, strong) UILabel *title;
  28. @property (nonatomic, strong) UILabel *message;
  29. @property (nonatomic, assign) BOOL didSetupConstraints;
  30. @end;
  31. @implementation CTAssetsPickerAccessDeniedView
  32. - (instancetype)initWithFrame:(CGRect)frame
  33. {
  34. if (self = [super initWithFrame:frame])
  35. {
  36. [self setupViews];
  37. }
  38. return self;
  39. }
  40. #pragma mark - Setup
  41. - (void)setupViews
  42. {
  43. UIImageView *padlock = [self padlockImageView];
  44. self.padlock = padlock;
  45. UILabel *title = [UILabel new];
  46. title.textColor = CTAssetsPikcerAccessDeniedViewTextColor;
  47. title.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
  48. title.textAlignment = NSTextAlignmentCenter;
  49. title.numberOfLines = 5;
  50. title.text = CTAssetsPickerLocalizedString(@"This app does not have access to your photos or videos.", nil);
  51. self.title = title;
  52. UILabel *message = [UILabel new];
  53. message.textColor = CTAssetsPikcerAccessDeniedViewTextColor;
  54. message.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
  55. message.textAlignment = NSTextAlignmentCenter;
  56. message.numberOfLines = 5;
  57. message.text = CTAssetsPickerLocalizedString(@"You can enable access in Privacy Settings.", nil);
  58. self.message = message;
  59. [self addSubview:self.padlock];
  60. [self addSubview:self.title];
  61. [self addSubview:self.message];
  62. }
  63. - (UIImageView *)padlockImageView
  64. {
  65. UIImage *image = [UIImage ctassetsPickerImageNamed:@"AccessDeniedViewLock"];
  66. image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
  67. UIImageView *padlock = [[UIImageView alloc] initWithImage:image];
  68. padlock.tintColor = CTAssetsPikcerAccessDeniedViewTextColor;
  69. return padlock;
  70. }
  71. #pragma mark - Update auto layout constraints
  72. - (void)updateConstraints
  73. {
  74. if (!self.didSetupConstraints)
  75. {
  76. [self autoCenterInSuperview];
  77. // suggested solution for issue #176
  78. [self autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:self.layoutMargins.top];
  79. [self autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:self.layoutMargins.bottom];
  80. [self.padlock autoAlignAxisToSuperviewAxis:ALAxisVertical];
  81. [self.padlock autoPinEdgeToSuperviewEdge:ALEdgeTop];
  82. [self.title autoAlignAxis:ALAxisVertical toSameAxisOfView:self.padlock];
  83. [self.title autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.padlock withOffset:20];
  84. [self.title autoPinEdgeToSuperviewEdge:ALEdgeLeading];
  85. [self.title autoPinEdgeToSuperviewEdge:ALEdgeTrailing];
  86. [self.message autoAlignAxis:ALAxisVertical toSameAxisOfView:self.padlock];
  87. [self.message autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.title withOffset:10];
  88. [self.message autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsZero excludingEdge:ALEdgeTop];
  89. self.didSetupConstraints = YES;
  90. }
  91. [super updateConstraints];
  92. }
  93. @end