Geen omschrijving

LGAlertViewShadowView.m 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // LGAlertViewShadowView.m
  3. // LGAlertView
  4. //
  5. //
  6. // The MIT License (MIT)
  7. //
  8. // Copyright © 2015 Grigory Lutkov <Friend.LGA@gmail.com>
  9. // (https://github.com/Friend-LGA/LGAlertView)
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining a copy
  12. // of this software and associated documentation files (the "Software"), to deal
  13. // in the Software without restriction, including without limitation the rights
  14. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  15. // copies of the Software, and to permit persons to whom the Software is
  16. // furnished to do so, subject to the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be included in all
  19. // copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  22. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  23. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  24. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  25. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  26. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  27. // SOFTWARE.
  28. //
  29. #import "LGAlertViewShadowView.h"
  30. @implementation LGAlertViewShadowView
  31. - (instancetype)init {
  32. self = [super init];
  33. if (self) {
  34. self.backgroundColor = UIColor.clearColor;
  35. self.userInteractionEnabled = NO;
  36. }
  37. return self;
  38. }
  39. - (void)drawRect:(CGRect)rect {
  40. [super drawRect:rect];
  41. if ((!self.strokeColor && !self.shadowColor) || (!self.strokeWidth && !self.shadowBlur)) return;
  42. CGContextRef context = UIGraphicsGetCurrentContext();
  43. // Fill
  44. if (self.shadowBlur && self.shadowColor) {
  45. CGContextSetShadowWithColor(context, CGSizeZero, self.shadowBlur, self.shadowColor.CGColor);
  46. }
  47. CGRect drawRect = CGRectMake(self.shadowBlur,
  48. self.shadowBlur,
  49. CGRectGetWidth(rect) - self.shadowBlur * 2.0,
  50. CGRectGetHeight(rect) - self.shadowBlur * 2.0);
  51. UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:drawRect
  52. byRoundingCorners:UIRectCornerAllCorners
  53. cornerRadii:CGSizeMake(self.cornerRadius, self.cornerRadius)];
  54. [path closePath];
  55. [UIColor.blackColor setFill];
  56. [path fill];
  57. // Remove black background
  58. CGContextSetShadowWithColor(context, CGSizeZero, 0.0, nil);
  59. CGContextSetBlendMode(context, kCGBlendModeClear);
  60. [path fill];
  61. CGContextSetBlendMode(context, kCGBlendModeNormal);
  62. }
  63. @end