UIXToolbarView.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //
  2. // UIXToolbarView.m
  3. // Reader v2.8.6
  4. //
  5. // Created by Julius Oklamcak on 2011-09-01.
  6. // Copyright © 2011-2015 Julius Oklamcak. All rights reserved.
  7. //
  8. // Permission is hereby granted, free of charge, to any person obtaining a copy
  9. // of this software and associated documentation files (the "Software"), to deal
  10. // in the Software without restriction, including without limitation the rights to
  11. // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  12. // of the Software, and to permit persons to whom the Software is furnished to
  13. // do so, subject to the following conditions:
  14. //
  15. // The above copyright notice and this permission notice shall be included in all
  16. // copies or substantial portions of the Software.
  17. //
  18. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  19. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  22. // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  23. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. //
  25. #import "ReaderConstants.h"
  26. #import "UIXToolbarView.h"
  27. #import <QuartzCore/QuartzCore.h>
  28. @implementation UIXToolbarView
  29. #pragma mark - Constants
  30. #define SHADOW_HEIGHT 4.0f
  31. #pragma mark - UIXToolbarView class methods
  32. + (Class)layerClass
  33. {
  34. #if (READER_FLAT_UI == FALSE) // Option
  35. return [CAGradientLayer class];
  36. #else
  37. return [CALayer class];
  38. #endif // end of READER_FLAT_UI Option
  39. }
  40. #pragma mark - UIXToolbarView instance methods
  41. - (instancetype)initWithFrame:(CGRect)frame
  42. {
  43. if ((self = [super initWithFrame:frame]))
  44. {
  45. self.autoresizesSubviews = YES;
  46. self.userInteractionEnabled = YES;
  47. self.contentMode = UIViewContentModeRedraw;
  48. self.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  49. if ([self.layer isKindOfClass:[CAGradientLayer class]])
  50. {
  51. self.backgroundColor = [UIColor clearColor];
  52. CAGradientLayer *layer = (CAGradientLayer *)self.layer;
  53. UIColor *liteColor = [UIColor colorWithWhite:0.92f alpha:0.8f];
  54. UIColor *darkColor = [UIColor colorWithWhite:0.32f alpha:0.8f];
  55. layer.colors = [NSArray arrayWithObjects:(id)liteColor.CGColor, (id)darkColor.CGColor, nil];
  56. CGRect shadowRect = self.bounds; shadowRect.origin.y += shadowRect.size.height; shadowRect.size.height = SHADOW_HEIGHT;
  57. UIXToolbarShadow *shadowView = [[UIXToolbarShadow alloc] initWithFrame:shadowRect];
  58. [self addSubview:shadowView]; // Add shadow to toolbar
  59. }
  60. else // Follow The Fuglyosity of Flat Fad
  61. {
  62. self.backgroundColor = [UIColor colorWithWhite:0.94f alpha:0.94f];
  63. CGRect lineRect = self.bounds; lineRect.origin.y += lineRect.size.height; lineRect.size.height = 1.0f;
  64. UIView *lineView = [[UIView alloc] initWithFrame:lineRect];
  65. lineView.autoresizesSubviews = NO;
  66. lineView.userInteractionEnabled = NO;
  67. lineView.contentMode = UIViewContentModeRedraw;
  68. lineView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  69. lineView.backgroundColor = [UIColor colorWithWhite:0.64f alpha:0.94f];
  70. [self addSubview:lineView];
  71. }
  72. }
  73. return self;
  74. }
  75. @end
  76. #pragma mark -
  77. //
  78. // UIXToolbarShadow class implementation
  79. //
  80. @implementation UIXToolbarShadow
  81. #pragma mark - UIXToolbarShadow class methods
  82. + (Class)layerClass
  83. {
  84. return [CAGradientLayer class];
  85. }
  86. #pragma mark - UIXToolbarShadow instance methods
  87. - (instancetype)initWithFrame:(CGRect)frame
  88. {
  89. if ((self = [super initWithFrame:frame]))
  90. {
  91. self.autoresizesSubviews = NO;
  92. self.userInteractionEnabled = NO;
  93. self.contentMode = UIViewContentModeRedraw;
  94. self.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  95. self.backgroundColor = [UIColor clearColor];
  96. CAGradientLayer *layer = (CAGradientLayer *)self.layer;
  97. UIColor *blackColor = [UIColor colorWithWhite:0.24f alpha:1.0f];
  98. UIColor *clearColor = [UIColor colorWithWhite:0.24f alpha:0.0f];
  99. layer.colors = [NSArray arrayWithObjects:(id)blackColor.CGColor, (id)clearColor.CGColor, nil];
  100. }
  101. return self;
  102. }
  103. @end