MCNavBarDelegate.swift 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. //
  2. // MCNavBarDelegate.swift
  3. // HCQuanfangtong
  4. //
  5. // Created by Apple on 2022/2/10.
  6. // Copyright © 2022 Jyp. All rights reserved.
  7. //
  8. import Foundation
  9. import RxSwift
  10. import RxCocoa
  11. import UIKit
  12. protocol MCNavBarDelegate: UIView{
  13. /// 样式
  14. var navStyle: MCNavBarStyle {get}
  15. /// 透明样式 != nil 包含透明样式
  16. var navTransparentStyle: MCNavBarTransparentColorStyle? { get set }
  17. /// 透明样式绑定的scrollView
  18. var navTransparentBinderedScrollView: UIScrollView? { get set }
  19. /// 高度
  20. var navBarHeightSubject: BehaviorSubject<CGFloat> { get }
  21. /// 返回按钮方法
  22. var navBarBackBlock: (()->Void)? {get set}
  23. /// 是否显示返回按钮
  24. var showNavBackBtn: Bool {get set}
  25. /// bar 高度
  26. func navBarHeight() -> CGFloat
  27. /// 设置标题
  28. /// - Parameter title: 标题文本,seachBar value or segment Index
  29. func setNavTitle(_ title: String?)
  30. func setNavSubTitle(_ title: String?)
  31. /// 设置右边按钮的标题 图片
  32. /// - Parameters:
  33. /// - title: <#title description#>
  34. /// - image: <#image description#>
  35. /// - index: <#index description#>
  36. func setNavRightBtnTitle(_ title: String?, image: String?, at index: Int)
  37. func setNavLeftBtnTitle(_ title: String?, image: String?, at index: Int)
  38. /// 新增按钮
  39. /// - Parameters:
  40. /// - title: <#title description#>
  41. /// - image: <#image description#>
  42. /// - tap: <#tap description#>
  43. /// - semantic
  44. /// - index: <#index description#>
  45. func insertNavRightBtn(_ title: String?, image: String?, tap: (()->Void)?, semantic: UISemanticContentAttribute?, at index: Int)
  46. func insertNavLeftBtn(_ title: String?, image: String?, tap: (()->Void)?, semantic: UISemanticContentAttribute?, at index: Int)
  47. /// 设置隐藏
  48. /// - Parameters:
  49. /// - hidden: <#hidden description#>
  50. /// - index: <#index description#>
  51. func setNavRightBtnHidden(_ hidden: Bool, at index: Int)
  52. func setNavLeftBtnHidden(_ hidden: Bool, at index: Int)
  53. /// 删除按钮
  54. /// - Parameter index: <#index description#>
  55. func deleteNavRightBtn(at index: Int)
  56. /// 删除左边按钮 不可以删除返回按钮,可以操作隐藏
  57. /// - Parameter index: <#index description#>
  58. func deleteNavLeftBtn(at index: Int)
  59. /// 获取右侧按钮的位置
  60. /// - Parameter index: <#index description#>
  61. func getNavRightBtnFrame(at index: Int) -> CGRect?
  62. /// 获取左侧按钮的位置
  63. /// - Parameter index: <#index description#>
  64. func getNavLeftBtnFrame(at index: Int) -> CGRect?
  65. /// 设置右边按钮 透明导航 图片
  66. /// - Parameters:
  67. /// - img: <#img description#>
  68. /// - index: <#index description#>
  69. func setNavRightBtnTransparentImage(_ img: String, at index: Int)
  70. /// 设置左边按钮 透明导航 图片
  71. /// - Parameters:
  72. /// - img: <#img description#>
  73. /// - index: <#index description#>
  74. func setNavLeftBtnTransparentImage(_ img: String, at index: Int)
  75. }
  76. class MCNavBarStyle: NSObject{
  77. var styleForBackgroundColor: UIColor = kThemeBlackColor
  78. var styleForTitleFont: UIFont = UIFont.pingFangSC(withWeight: FontWeightStyle.medium, size: 19)
  79. var styleForTitleColor: UIColor = kThemeWhiteColor
  80. var styleForSubTitleFont: UIFont = UIFont.pingFangSC(withWeight: FontWeightStyle.medium, size: 13)
  81. var styleForSubTitleColor: UIColor = UIColor.init(red: 1, green: 1, blue: 1, alpha: 0.6)
  82. var styleForBtnTitleColor: UIColor = kThemeWhiteColor
  83. var styleForBtnTitleFont: UIFont = UIFont.pingFangSC(withWeight: FontWeightStyle.medium, size: 16)
  84. /// 内容边距
  85. var styleForContentEdge: UIEdgeInsets = UIEdgeInsets.init(top: 0, left: 10, bottom: 0, right: 10)
  86. /// 按钮最小点击区域宽度
  87. var styleForTapMinWidth: CGFloat = 30
  88. /// 文字和图片的距离
  89. var styleForBtnTitleAndImageDistance: CGFloat = 2
  90. var styleForBtnEdgeInset: UIEdgeInsets = UIEdgeInsets.init(top: 0, left: 2, bottom: 0, right: 2)
  91. /// 元素间距
  92. var styleForElementSpace: CGFloat = 5
  93. /// 标题和子标题的间距
  94. var styleForTitleAndSubTitleDistance: CGFloat = 5
  95. /// 返回图片
  96. var styleForBackImage: UIImage = UIImage.init(named: "白色返回")!
  97. /// 返回按钮的内边距
  98. var styleForBackEdgeInset: UIEdgeInsets = UIEdgeInsets.init(top: 0, left: 16, bottom: 0, right: 2)
  99. var styleForBackMinWidth: CGFloat = 60
  100. /// 中间区域是否居中,默认居中
  101. var styleForContentViewIsMiddle: Bool = true
  102. /// -1 代表不限制宽度
  103. var styleForContentViewWidth: CGFloat = -1
  104. /// 当出现需要放大显示时,采用此放大比例
  105. var styleForScaling: CGFloat = 1.2
  106. /// 放大之前的字体颜色
  107. var styleForScalingBeforeTitleColor: UIColor = UIColor.init(red: 1, green: 1, blue: 1, alpha: 0.6)
  108. /// <#Description#>
  109. var styleForSearchHeight: CGFloat = 30
  110. /// input样式的背景颜色
  111. var styleForSearchBackgroundColor: UIColor = kThemeWhiteColor
  112. /// input样式的背景颜色搜索图片样式
  113. var styleForSearchSearchImage: UIImage = UIImage.init(named: "new_search_gray")!
  114. /// input样式placeholderColor
  115. var styleForSearchPlaceholderColor: UIColor = kThemeOfTextPlaceholderColor
  116. /// input样式输入框的文本大小
  117. var styleForSearchTextFont: UIFont = UIFont.pingFangSC(withWeight: FontWeightStyle.regular, size: 14)
  118. static var whiteStyle: MCNavBarStyle = {
  119. let style = MCNavBarStyle()
  120. style.styleForBackgroundColor = kThemeWhiteColor
  121. style.styleForTitleColor = kThemeOfTextBlackColor
  122. style.styleForScalingBeforeTitleColor = kThemeOfTextLightColor
  123. style.styleForBtnTitleColor = kThemeOfTextBlackColor
  124. style.styleForBackImage = UIImage.init(named: "icon_back_white_nav_bar")!
  125. // style.styleForContentEdge = UIEdgeInsets.init(top: 0, left: 16, bottom: 0, right: 16)
  126. return style
  127. }()
  128. }
  129. /// 透明颜色样式
  130. class MCNavBarTransparentColorStyle: NSObject{
  131. static var blackStyle: MCNavBarTransparentColorStyle = {
  132. let style = MCNavBarTransparentColorStyle.init()
  133. style.styleForBackgroundColor = UIColor.clear
  134. style.styleForTitleColor = kThemeOfTextBlackColor
  135. style.styleForSubTitleColor = kThemeOfTextBlackColor
  136. style.styleForBtnTitleColor = kThemeOfTextBlackColor
  137. style.styleForBackImage = UIImage.init(named: "渠道选择返回箭头")!
  138. return style
  139. }()
  140. /// 滑动距离 当达到此值时切换为正常的navBar
  141. var styleForScrollDistanceChange: CGFloat = 100
  142. var styleForBackgroundColor: UIColor = UIColor.clear
  143. var styleForTitleColor: UIColor = kThemeWhiteColor
  144. var styleForSubTitleColor: UIColor = UIColor.init(red: 1, green: 1, blue: 1, alpha: 0.6)
  145. var styleForBtnTitleColor: UIColor = kThemeWhiteColor
  146. var styleForBackImage: UIImage = UIImage.init(named: "箭头返回")!
  147. }
  148. /// 任何按钮都可以关联弹窗的代理,以操作弹窗显示,消失,以及获取选定的字符串和位置
  149. protocol MCPopBeAssociatedDelegate : NSObjectProtocol{
  150. /// 是否显示
  151. var isShow: Bool! {get}
  152. /// 信号 : show or hidden
  153. var binderIsShow: PublishSubject<Bool>! {get}
  154. /// 信号 : 单选
  155. var binderValue: PublishSubject<MCPopSelectedModel?>? {get}
  156. /// 信号 : 单选 多选
  157. var binderValues: PublishSubject<[MCPopSelectedModel]?>? {get}
  158. /// 发送信号 binderValues 会自动发送信号
  159. /// - Parameter str: <#str description#>
  160. func sendSingle(with str: String)
  161. /// 设置数据源
  162. /// - Parameter sources: <#sources description#>
  163. func setDataSource<T>(with sources: T) -> Bool
  164. /// 获取数据源
  165. /// - Returns: <#description#>
  166. func getDataSource() -> Any?
  167. /// 显示
  168. @discardableResult
  169. func show() -> Self
  170. /// 隐藏
  171. func hidden()
  172. }
  173. /// 弹窗选定的值
  174. @objcMembers class MCPopSelectedModel: NSObject{
  175. /// 字符串
  176. var name: String?
  177. /// 在数据源的位置,有可能为空
  178. var index: NSNumber?
  179. /// 有可能为空
  180. var id: String?
  181. /// 初始化
  182. /// - Parameters:
  183. /// - name: <#name description#>
  184. /// - index: <#index description#>
  185. init(name: String?, index: NSNumber? = nil, id: String? = nil){
  186. self.name = name
  187. self.index = index
  188. self.id = id
  189. super.init()
  190. }
  191. override var description: String{
  192. "name = \(String(describing: self.name)), index = \(String(describing: self.index)), id = \(String(describing: self.id))"
  193. }
  194. }
  195. @objcMembers public class MCPopSourceModel: NSObject{
  196. /// 名字
  197. var name: String?
  198. /// id值
  199. var id: String?
  200. /// 子数据源
  201. var subItems: [MCPopSourceModel]?
  202. convenience init(name: String?, id: String?){
  203. self.init(name: name, id: id, subItems: nil)
  204. }
  205. init(name: String?, id: String?, subItems: [MCPopSourceModel]?){
  206. self.name = name
  207. self.id = id
  208. self.subItems = subItems
  209. super.init()
  210. }
  211. }