OJAStyle.swift 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. //
  2. // FVStyle.swift
  3. // FanVideo
  4. //
  5. // Created by luxiaoming on 2016/12/14.
  6. // Copyright © 2016年 luxiaoming. All rights reserved.
  7. //
  8. import OJASwiftKit
  9. import SVProgressHUD
  10. import UIKit
  11. // 这些是设计规范定义的基础颜色,一般不直接使用
  12. private let kWSSColorMain = OJSColor(hexRGBValue: 0xFF1E50) // 主色红色
  13. private let kWSSColorBackground = OJSColor(hexRGBValue: 0x1E1E2A) // 主背景色
  14. struct OJATextColor {
  15. static let colorMain = kWSSColorMain
  16. static let colorWhite = UIColor.white
  17. static let color18 = OJSColor(hexRGBValue: 0x181818)
  18. static let color3 = OJSColor(hexRGBValue: 0x333333)
  19. static let color6 = OJSColor(hexRGBValue: 0x666666)
  20. static let color8 = OJSColor(hexRGBValue: 0x888888)
  21. static let color9 = OJSColor(hexRGBValue: 0x999999)
  22. static let color9a = OJSColor(hexRGBValue: 0x9a9a9a)
  23. static let colorC = OJSColor(hexRGBValue: 0xCCCCCC)
  24. static let colorCD = OJSColor(hexRGBValue: 0xCDCDCD)
  25. static let color4C = OJSColor(hexRGBValue: 0x4C4C4C)
  26. static let color0C = OJSColor(hexRGBValue: 0x0C0C0C)
  27. static let colorA = OJSColor(hexRGBValue: 0xAAAAAA)
  28. static let navTitleColor = OJATextColor.colorWhite
  29. }
  30. struct OJAFont {
  31. static let font30 = UIFont.systemFont(ofSize: 30)
  32. static let font24 = UIFont.systemFont(ofSize: 24)
  33. static let font22 = UIFont.systemFont(ofSize: 22)
  34. static let font20 = UIFont.systemFont(ofSize: 20)
  35. static let font18 = UIFont.systemFont(ofSize: 18)
  36. static let font17 = UIFont.systemFont(ofSize: 17)
  37. static let font16 = UIFont.systemFont(ofSize: 16)
  38. static let font15 = UIFont.systemFont(ofSize: 15)
  39. static let font14 = UIFont.systemFont(ofSize: 14)
  40. static let font13 = UIFont.systemFont(ofSize: 13)
  41. static let font12 = UIFont.systemFont(ofSize: 12)
  42. static let font11 = UIFont.systemFont(ofSize: 11)
  43. static let font10 = UIFont.systemFont(ofSize: 10)
  44. static let font9 = UIFont.systemFont(ofSize: 9)
  45. static let font8 = UIFont.systemFont(ofSize: 8)
  46. static func fontB(_ size: CGFloat) -> UIFont {
  47. return UIFont.boldSystemFont(ofSize: size)
  48. }
  49. }
  50. struct OJAStyle {
  51. static let mainColor = kWSSColorMain
  52. static let whiteColor = UIColor.white
  53. static let backgroundColor = kWSSColorBackground
  54. static let searchColor = OJSColor(hexRGBValue: 0x353541)
  55. static let tableSeparatorColor = OJSColor(hexRGBValue: 0x30303C)
  56. static let subIconColor = OJSColor(hexRGBValue: 0x808080)
  57. static let halfBlackColor = UIColor(white: 0, alpha: 0.5)
  58. static let divideLine = OJSColor(hexRGBValue: 0xEEEEEE)
  59. static let LRCommonMargin: CGFloat = 16.0
  60. static let tabBarSelectedAttributeDict = [NSAttributedString.Key.foregroundColor: OJATextColor.colorWhite.withAlphaComponent(0.8),
  61. NSAttributedString.Key.font: OJAFont.font10]
  62. static let tabBarNormalAttributeDict = [NSAttributedString.Key.foregroundColor: OJATextColor.colorWhite.withAlphaComponent(0.3),
  63. NSAttributedString.Key.font: OJAFont.font10]
  64. static let navAttributeDict = [NSAttributedString.Key.foregroundColor: OJATextColor.navTitleColor,
  65. NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 18)]
  66. }
  67. struct WSSVideoDefine {
  68. static let maxDuration: Float = 15
  69. static let videoFPS: Int = OJADeviceHardware.isDeviceiPhone6sOrHigher() ? 30 : 25
  70. static let maxFrameCount: Int = Int(WSSVideoDefine.maxDuration) * WSSVideoDefine.videoFPS
  71. // 注意宽高都应该是16的整数倍,否则录制出来的视频会有绿边
  72. static let size540P: CGSize = CGSize(width: 544, height: 960)
  73. }
  74. /*
  75. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!
  76. 因为行距为22,文字大小为15,但是label的文字是垂直居中的,所以文字距离label上鞋边距各有3.5,
  77. UI上标注的间距是不包括这3.5的, 计算高度时,如果是跟label之间的间距,记得减去3
  78. */
  79. /// 设置app全局样式 注意:要在使用到UINavigationBar或者UITabBar之前设置
  80. func setupAppAppearance() {
  81. UITabBarItem.appearance().setTitleTextAttributes(OJAStyle.tabBarSelectedAttributeDict, for: .selected)
  82. UITabBarItem.appearance().setTitleTextAttributes(OJAStyle.tabBarNormalAttributeDict, for: .normal)
  83. UITabBar.appearance().backgroundImage = UIImage.oja_image(with: OJAStyle.backgroundColor)
  84. // UITabBar.appearance().shadowImage = UIImage.oja_image(with: OJSColor(hexRGBValue: 0xdcdcdc))//看文档,这一句可以用来去掉tabBar上面默认的线条
  85. UITabBar.appearance().isTranslucent = false
  86. UINavigationBar.appearance().shadowImage = UIImage.oja_image(with: OJAStyle.backgroundColor) // 这一句可以去掉导航栏最下面的线
  87. UINavigationBar.appearance().setBackgroundImage(UIImage.oja_image(with: OJAStyle.backgroundColor), for: .default)
  88. UINavigationBar.appearance().tintColor = OJATextColor.navTitleColor
  89. UINavigationBar.appearance().titleTextAttributes = OJAStyle.navAttributeDict
  90. UINavigationBar.appearance().backIndicatorImage = R.image.nav_back()
  91. UINavigationBar.appearance().backIndicatorTransitionMaskImage = R.image.nav_back()
  92. // 这里是为了解决在一些界面隐藏了导航栏之后,再push到下一个有导航控制器的界面时, 有可能会显示出Back的title
  93. // https://stackoverflow.com/questions/19078995/removing-the-title-text-of-an-ios-uibarbuttonitem
  94. UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffset(horizontal: -200, vertical: 0), for: .default)
  95. // 还是不用appearance修改label设置了,感觉是在自己给自己挖坑,需要优化的地方手动优化吧
  96. }
  97. @objcMembers
  98. class WSSStyle: NSObject {
  99. static let shared = WSSStyle()
  100. private override init() {
  101. super.init()
  102. }
  103. /// 首页cell的descLabel属性,字体13,行距4
  104. var homeCellDescAttributeDict: [NSAttributedString.Key: Any] = {
  105. let style = NSMutableParagraphStyle()
  106. style.lineSpacing = 4
  107. let dict = [NSAttributedString.Key.font: OJAFont.font13,
  108. NSAttributedString.Key.foregroundColor: OJATextColor.colorWhite,
  109. NSAttributedString.Key.paragraphStyle: style]
  110. return dict
  111. }()
  112. }
  113. extension UILabel {
  114. /// 这个是为了减少图层混合提高显示性能的
  115. func setOpaqueBackgroundColor(color: UIColor = UIColor.white) {
  116. backgroundColor = color
  117. layer.masksToBounds = true
  118. }
  119. }
  120. extension UIImageView {
  121. /// 这个是为了减少图层混合提高显示性能的
  122. func setOpaqueBackgroundColor(color: UIColor = UIColor.white) {
  123. backgroundColor = color
  124. }
  125. }
  126. extension UIButton {
  127. class func WSSDefaultNextButton(withTitle title: String?) -> UIButton {
  128. let nextButton = UIButton(frame: CGRect(x: kOJSScreenWidth - 16 - 60, y: kOJSStatusBarHeight + 7, width: 60, height: 29))
  129. nextButton.setTitle(title, for: .normal)
  130. nextButton.setBackgroundImage(UIImage.oja_image(with: OJAStyle.mainColor), for: .normal)
  131. nextButton.titleLabel?.font = OJAFont.font14
  132. nextButton.layer.cornerRadius = 4
  133. nextButton.layer.masksToBounds = true
  134. return nextButton
  135. }
  136. }
  137. extension HMSegmentedControl {
  138. func setupDefaultMTStyle() {
  139. backgroundColor = UIColor.clear
  140. type = .text
  141. selectionStyle = .textWidthStripe
  142. segmentWidthStyle = .dynamic
  143. selectionIndicatorLocation = .down
  144. selectionIndicatorHeight = 3
  145. selectionIndicatorColor = OJATextColor.colorMain
  146. selectedTitleTextAttributes = [NSAttributedString.Key.foregroundColor: OJATextColor.colorMain,
  147. NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 15)]
  148. titleTextAttributes = [NSAttributedString.Key.foregroundColor: OJATextColor.colorWhite,
  149. NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 15)]
  150. segmentEdgeInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 16) // 注意,segmentEdgeInset是针对每个segment的属性,而不是针对整个View的属性
  151. }
  152. func setupTabBarStyle() {
  153. backgroundColor = OJAStyle.backgroundColor
  154. type = .text
  155. selectionStyle = .textWidthStripe
  156. segmentWidthStyle = .fixed // yong fixed是为了在contentSize小于frame时能时segment均匀分布
  157. selectionIndicatorLocation = .down
  158. selectionIndicatorHeight = 3
  159. selectionIndicatorEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: -5, right: 0)
  160. selectionIndicatorColor = OJATextColor.colorWhite
  161. selectedTitleTextAttributes = OJAStyle.tabBarSelectedAttributeDict
  162. titleTextAttributes = OJAStyle.tabBarNormalAttributeDict
  163. segmentEdgeInset = UIEdgeInsets.zero // 注意,segmentEdgeInset是针对每个segment的属性,而不是针对整个View的属性
  164. }
  165. func setupPasterStyle() {
  166. backgroundColor = UIColor.clear
  167. type = .text
  168. selectionStyle = .fullWidthStripe
  169. segmentWidthStyle = .fixed // yong fixed是为了在contentSize小于frame时能时segment均匀分布
  170. selectionIndicatorLocation = .down
  171. selectionIndicatorHeight = 3
  172. selectionIndicatorEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: -5, right: 0)
  173. selectionIndicatorColor = OJATextColor.colorMain
  174. selectedTitleTextAttributes = [NSAttributedString.Key.foregroundColor: OJATextColor.colorMain,
  175. NSAttributedString.Key.font: OJAFont.font16]
  176. titleTextAttributes = [NSAttributedString.Key.foregroundColor: OJATextColor.color9,
  177. NSAttributedString.Key.font: OJAFont.font16]
  178. segmentEdgeInset = UIEdgeInsets.zero // 注意,segmentEdgeInset是针对每个segment的属性,而不是针对整个View的属性
  179. }
  180. }
  181. extension UILabel {
  182. func setupWithHomeCellDescAttributeDict(text: String?) {
  183. if let text = text {
  184. attributedText = NSAttributedString(string: text, attributes: WSSStyle.shared.homeCellDescAttributeDict)
  185. } else {
  186. attributedText = nil
  187. }
  188. }
  189. }
  190. extension UITextView {
  191. }
  192. extension UIColor {
  193. }