UIPopBackgroundView.swift 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //
  2. // UIPopBackgroundView.swift
  3. // ComPDFKit_Tools
  4. //
  5. // Copyright © 2014-2024 PDF Technologies, Inc. All Rights Reserved.
  6. //
  7. // THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  8. // AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  9. // UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  10. // This notice may not be removed from this file.
  11. //
  12. import UIKit
  13. class UIPopBackgroundView: UIPopoverBackgroundView {
  14. var fArrowOffset: CGFloat = 0
  15. var direction: UIPopoverArrowDirection = .any
  16. class func wantsDefaultContentAppearance() -> Bool {
  17. return false
  18. }
  19. override class func arrowBase() -> CGFloat {
  20. return 0
  21. }
  22. override class func contentViewInsets() -> UIEdgeInsets {
  23. return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
  24. }
  25. override class func arrowHeight() -> CGFloat {
  26. return 0
  27. }
  28. override var arrowDirection: UIPopoverArrowDirection {
  29. get {
  30. return direction
  31. }
  32. set {
  33. direction = newValue
  34. }
  35. }
  36. override var arrowOffset: CGFloat {
  37. get {
  38. return fArrowOffset
  39. }
  40. set {
  41. fArrowOffset = newValue
  42. }
  43. }
  44. override init(frame: CGRect) {
  45. super.init(frame: frame)
  46. backgroundColor = UIColor.clear
  47. layer.cornerRadius = 3.0
  48. let shadowView = UIView(frame: frame)
  49. shadowView.backgroundColor = backgroundColor
  50. addSubview(shadowView)
  51. shadowView.layer.shadowColor = UIColor(red: 163.0/255.0, green: 163.0/255.0, blue: 163.0/255.0, alpha: 0.5).cgColor
  52. shadowView.layer.shadowOpacity = 1.0
  53. shadowView.layer.shadowRadius = 1.0
  54. shadowView.layer.shadowOffset = CGSize(width: 2, height: 1)
  55. shadowView.layer.cornerRadius = 3.0
  56. let maskLayer = CALayer()
  57. maskLayer.frame = shadowView.layer.bounds
  58. maskLayer.masksToBounds = true
  59. shadowView.layer.addSublayer(maskLayer)
  60. }
  61. required init?(coder: NSCoder) {
  62. fatalError("init(coder:) has not been implemented")
  63. }
  64. override func layoutSubviews() {
  65. super.layoutSubviews()
  66. }
  67. }