No Description

FFAlertController.swift 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. //
  2. // FFAlertController.swift
  3. // FFAlert
  4. //
  5. // Created by FFIB on 2017/11/13.
  6. // Copyright © 2017年 FFIB. All rights reserved.
  7. //
  8. import UIKit
  9. //public enum FFAlertStyle {
  10. // case actionSheet
  11. // case alert
  12. //}
  13. //
  14. //public class FFAlertController: UIViewController {
  15. //
  16. //// private
  17. // private var transitionDelegate: FFTransitioning
  18. // private var alert: UIView & FFAlertRepresentable
  19. //
  20. // public var alertStyle: FFAlertStyle
  21. // public var contentEdgeInsets: UIEdgeInsets {
  22. // get { return self.alert.contentEdgInsets }
  23. // set { alert.contentEdgInsets = newValue }
  24. // }
  25. //
  26. // public var attributedTitle: NSAttributedString? {
  27. // get { return self.alert.title }
  28. // set { self.alert.title = newValue }
  29. // }
  30. //
  31. // public var attributedMessage: NSAttributedString? {
  32. // get { return self.alert.message }
  33. // set { self.alert.message = newValue }
  34. // }
  35. //
  36. // public override var title: String? {
  37. // get { return attributedTitle?.string }
  38. // set { attributedTitle = NSAttributedString(string: newValue ?? "", attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 17), NSAttributedString.Key.foregroundColor: UIColor.init(red: 0.2, green: 0.2, blue: 0.2, alpha: 1.0)]) }
  39. // }
  40. //
  41. // public var message: String? {
  42. // get { return attributedMessage?.string }
  43. // set { attributedMessage = NSAttributedString(string: newValue ?? "", attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 14), NSAttributedString.Key.foregroundColor: UIColor.init(red: 0.6, green: 0.6, blue: 0.6, alpha: 1.0)]) }
  44. // }
  45. //
  46. // private var alertActions: [FFAlertAction] {
  47. // get { return alert.alertActions }
  48. // set { alert.alertActions = newValue }
  49. // }
  50. //
  51. // public var alertEdgInsets: (left: CGFloat, right: CGFloat) {
  52. // get { return alert.edgInsets }
  53. // set { alert.edgInsets = newValue }
  54. // }
  55. //
  56. // convenience init(title: String? = nil, message: String? = nil,
  57. // customView: UIView,
  58. // alertStyle: FFAlertStyle = .alert) {
  59. // self.init(alertStyle: alertStyle)
  60. // self.alert.contentView = customView
  61. // self.title = title
  62. // self.message = message
  63. // }
  64. //
  65. // convenience init(title: String? = nil, message: String? = nil,
  66. // alertStyle: FFAlertStyle = .alert) {
  67. // self.init(alertStyle: alertStyle)
  68. // self.title = title
  69. // self.message = message
  70. //
  71. // }
  72. //
  73. // convenience init(attributedTitle: NSAttributedString? = nil,
  74. // attributedMessage: NSAttributedString? = nil,
  75. // alertStyle: FFAlertStyle = .alert) {
  76. // self.init(alertStyle: alertStyle)
  77. // self.attributedTitle = attributedTitle
  78. // self.attributedMessage = attributedMessage
  79. // }
  80. //
  81. // private init(alertStyle: FFAlertStyle) {
  82. // switch alertStyle {
  83. // case .alert:
  84. // self.alert = FFAlertView()
  85. // case .actionSheet:
  86. // self.alert = FFSheetView()
  87. // }
  88. // self.alertStyle = alertStyle
  89. // self.transitionDelegate = FFTransitioning(alertStyle: alertStyle)
  90. // super.init(nibName: nil, bundle: nil)
  91. // commonInit()
  92. // }
  93. //
  94. // required public init?(coder aDecoder: NSCoder) {
  95. // fatalError("init(coder:) has not been implemented")
  96. // }
  97. //
  98. // private func commonInit() {
  99. // self.modalPresentationStyle = .custom
  100. // self.transitioningDelegate = self.transitionDelegate
  101. // }
  102. //
  103. // override public var preferredStatusBarStyle: UIStatusBarStyle {
  104. // return presentingViewController?.preferredStatusBarStyle ?? .default
  105. // }
  106. //
  107. // override public var supportedInterfaceOrientations: UIInterfaceOrientationMask {
  108. // return presentingViewController?.supportedInterfaceOrientations ?? super.supportedInterfaceOrientations
  109. // }
  110. //
  111. // override public func viewDidLoad() {
  112. // super.viewDidLoad()
  113. // configurationOfAlertView()
  114. // let tap = UITapGestureRecognizer(target: self, action: #selector(disappear))
  115. // tap.delegate = self
  116. // view.addGestureRecognizer(tap)
  117. // }
  118. //
  119. // @objc
  120. // func disappear() {
  121. // dismiss(animated: true, completion: nil)
  122. // }
  123. //
  124. // func configurationOfAlertView() {
  125. // view.addSubview(alert)
  126. // alert.translatesAutoresizingMaskIntoConstraints = false
  127. // alert.backgroundColor = UIColor.white
  128. // switch alertStyle {
  129. // case .actionSheet:
  130. // NSLayoutConstraint.activate(
  131. // [NSLayoutConstraint(item: alert, attribute: .leading,
  132. // relatedBy: .equal,
  133. // toItem: view, attribute: .leading,
  134. // multiplier: 1, constant: alertEdgInsets.left),
  135. // NSLayoutConstraint(item: alert, attribute: .bottom,
  136. // relatedBy: .equal,
  137. // toItem: view, attribute: .bottom,
  138. // multiplier: 1, constant: 0),
  139. // NSLayoutConstraint(item: alert, attribute: .trailing,
  140. // relatedBy: .equal,
  141. // toItem: view, attribute: .trailing,
  142. // multiplier: 1, constant: -alertEdgInsets.right),
  143. // NSLayoutConstraint(item: alert, attribute: .height,
  144. // relatedBy: .lessThanOrEqual,
  145. // toItem: view, attribute: .height,
  146. // multiplier: 1, constant: 0)]
  147. // )
  148. // alert.setContentCompressionResistancePriority(.required, for: .vertical)
  149. // case .alert:
  150. // NSLayoutConstraint.activate(
  151. // [NSLayoutConstraint(item: alert, attribute: .leading,
  152. // relatedBy: .equal,
  153. // toItem: view, attribute: .leading,
  154. // multiplier: 1, constant: alertEdgInsets.left),
  155. // NSLayoutConstraint(item: alert, attribute: .centerY,
  156. // relatedBy: .equal,
  157. // toItem: view, attribute: .centerY,
  158. // multiplier: 1, constant: 0),
  159. // NSLayoutConstraint(item: alert, attribute: .trailing,
  160. // relatedBy: .equal,
  161. // toItem: view, attribute: .trailing,
  162. // multiplier: 1, constant: -alertEdgInsets.right),
  163. // NSLayoutConstraint(item: alert, attribute: .height,
  164. // relatedBy: .lessThanOrEqual,
  165. // toItem: view, attribute: .height,
  166. // multiplier: 1, constant: 0)]
  167. // )
  168. // alert.setContentCompressionResistancePriority(.required, for: .vertical)
  169. // }
  170. //
  171. // }
  172. //
  173. // func addAlertAction(alertAction: FFAlertAction) {
  174. // alertActions.append(alertAction)
  175. // }
  176. //}
  177. //
  178. //extension FFAlertController: UIGestureRecognizerDelegate {
  179. // public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
  180. // if alert.frame.contains(touch.location(in: view)) {
  181. // return false
  182. // }
  183. // return true
  184. // }
  185. //}