123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- //
- // FVStyle.swift
- // FanVideo
- //
- // Created by luxiaoming on 2016/12/14.
- // Copyright © 2016年 luxiaoming. All rights reserved.
- //
- import OJASwiftKit
- import SVProgressHUD
- import UIKit
- // 这些是设计规范定义的基础颜色,一般不直接使用
- private let kWSSColorMain = OJSColor(hexRGBValue: 0xFF1E50) // 主色红色
- private let kWSSColorBackground = OJSColor(hexRGBValue: 0x1E1E2A) // 主背景色
- struct OJATextColor {
- static let colorMain = kWSSColorMain
- static let colorWhite = UIColor.white
- static let color18 = OJSColor(hexRGBValue: 0x181818)
- static let color3 = OJSColor(hexRGBValue: 0x333333)
- static let color6 = OJSColor(hexRGBValue: 0x666666)
- static let color8 = OJSColor(hexRGBValue: 0x888888)
- static let color9 = OJSColor(hexRGBValue: 0x999999)
- static let color9a = OJSColor(hexRGBValue: 0x9a9a9a)
- static let colorC = OJSColor(hexRGBValue: 0xCCCCCC)
- static let colorCD = OJSColor(hexRGBValue: 0xCDCDCD)
- static let color4C = OJSColor(hexRGBValue: 0x4C4C4C)
- static let color0C = OJSColor(hexRGBValue: 0x0C0C0C)
- static let colorA = OJSColor(hexRGBValue: 0xAAAAAA)
- static let navTitleColor = OJATextColor.colorWhite
- }
- struct OJAFont {
- static let font30 = UIFont.systemFont(ofSize: 30)
- static let font24 = UIFont.systemFont(ofSize: 24)
- static let font22 = UIFont.systemFont(ofSize: 22)
- static let font20 = UIFont.systemFont(ofSize: 20)
- static let font18 = UIFont.systemFont(ofSize: 18)
- static let font17 = UIFont.systemFont(ofSize: 17)
- static let font16 = UIFont.systemFont(ofSize: 16)
- static let font15 = UIFont.systemFont(ofSize: 15)
- static let font14 = UIFont.systemFont(ofSize: 14)
- static let font13 = UIFont.systemFont(ofSize: 13)
- static let font12 = UIFont.systemFont(ofSize: 12)
- static let font11 = UIFont.systemFont(ofSize: 11)
- static let font10 = UIFont.systemFont(ofSize: 10)
- static let font9 = UIFont.systemFont(ofSize: 9)
- static let font8 = UIFont.systemFont(ofSize: 8)
- static func fontB(_ size: CGFloat) -> UIFont {
- return UIFont.boldSystemFont(ofSize: size)
- }
- }
- struct OJAStyle {
- static let mainColor = kWSSColorMain
- static let whiteColor = UIColor.white
- static let backgroundColor = kWSSColorBackground
- static let searchColor = OJSColor(hexRGBValue: 0x353541)
- static let tableSeparatorColor = OJSColor(hexRGBValue: 0x30303C)
- static let subIconColor = OJSColor(hexRGBValue: 0x808080)
- static let halfBlackColor = UIColor(white: 0, alpha: 0.5)
- static let divideLine = OJSColor(hexRGBValue: 0xEEEEEE)
- static let LRCommonMargin: CGFloat = 16.0
- static let tabBarSelectedAttributeDict = [NSAttributedString.Key.foregroundColor: OJATextColor.colorWhite.withAlphaComponent(0.8),
- NSAttributedString.Key.font: OJAFont.font10]
- static let tabBarNormalAttributeDict = [NSAttributedString.Key.foregroundColor: OJATextColor.colorWhite.withAlphaComponent(0.3),
- NSAttributedString.Key.font: OJAFont.font10]
- static let navAttributeDict = [NSAttributedString.Key.foregroundColor: OJATextColor.navTitleColor,
- NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 18)]
- }
- struct WSSVideoDefine {
- static let maxDuration: Float = 15
- static let videoFPS: Int = OJADeviceHardware.isDeviceiPhone6sOrHigher() ? 30 : 25
- static let maxFrameCount: Int = Int(WSSVideoDefine.maxDuration) * WSSVideoDefine.videoFPS
- // 注意宽高都应该是16的整数倍,否则录制出来的视频会有绿边
- static let size540P: CGSize = CGSize(width: 544, height: 960)
- }
- /*
- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!
- 因为行距为22,文字大小为15,但是label的文字是垂直居中的,所以文字距离label上鞋边距各有3.5,
- UI上标注的间距是不包括这3.5的, 计算高度时,如果是跟label之间的间距,记得减去3
- */
- /// 设置app全局样式 注意:要在使用到UINavigationBar或者UITabBar之前设置
- func setupAppAppearance() {
- UITabBarItem.appearance().setTitleTextAttributes(OJAStyle.tabBarSelectedAttributeDict, for: .selected)
- UITabBarItem.appearance().setTitleTextAttributes(OJAStyle.tabBarNormalAttributeDict, for: .normal)
- UITabBar.appearance().backgroundImage = UIImage.oja_image(with: OJAStyle.backgroundColor)
- // UITabBar.appearance().shadowImage = UIImage.oja_image(with: OJSColor(hexRGBValue: 0xdcdcdc))//看文档,这一句可以用来去掉tabBar上面默认的线条
- UITabBar.appearance().isTranslucent = false
- UINavigationBar.appearance().shadowImage = UIImage.oja_image(with: OJAStyle.backgroundColor) // 这一句可以去掉导航栏最下面的线
- UINavigationBar.appearance().setBackgroundImage(UIImage.oja_image(with: OJAStyle.backgroundColor), for: .default)
- UINavigationBar.appearance().tintColor = OJATextColor.navTitleColor
- UINavigationBar.appearance().titleTextAttributes = OJAStyle.navAttributeDict
- UINavigationBar.appearance().backIndicatorImage = R.image.nav_back()
- UINavigationBar.appearance().backIndicatorTransitionMaskImage = R.image.nav_back()
- // 这里是为了解决在一些界面隐藏了导航栏之后,再push到下一个有导航控制器的界面时, 有可能会显示出Back的title
- // https://stackoverflow.com/questions/19078995/removing-the-title-text-of-an-ios-uibarbuttonitem
- UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffset(horizontal: -200, vertical: 0), for: .default)
- // 还是不用appearance修改label设置了,感觉是在自己给自己挖坑,需要优化的地方手动优化吧
- }
- @objcMembers
- class WSSStyle: NSObject {
- static let shared = WSSStyle()
- private override init() {
- super.init()
- }
- /// 首页cell的descLabel属性,字体13,行距4
- var homeCellDescAttributeDict: [NSAttributedString.Key: Any] = {
- let style = NSMutableParagraphStyle()
- style.lineSpacing = 4
- let dict = [NSAttributedString.Key.font: OJAFont.font13,
- NSAttributedString.Key.foregroundColor: OJATextColor.colorWhite,
- NSAttributedString.Key.paragraphStyle: style]
- return dict
- }()
- }
- extension UILabel {
- /// 这个是为了减少图层混合提高显示性能的
- func setOpaqueBackgroundColor(color: UIColor = UIColor.white) {
- backgroundColor = color
- layer.masksToBounds = true
- }
- }
- extension UIImageView {
- /// 这个是为了减少图层混合提高显示性能的
- func setOpaqueBackgroundColor(color: UIColor = UIColor.white) {
- backgroundColor = color
- }
- }
- extension UIButton {
- class func WSSDefaultNextButton(withTitle title: String?) -> UIButton {
- let nextButton = UIButton(frame: CGRect(x: kOJSScreenWidth - 16 - 60, y: kOJSStatusBarHeight + 7, width: 60, height: 29))
- nextButton.setTitle(title, for: .normal)
- nextButton.setBackgroundImage(UIImage.oja_image(with: OJAStyle.mainColor), for: .normal)
- nextButton.titleLabel?.font = OJAFont.font14
- nextButton.layer.cornerRadius = 4
- nextButton.layer.masksToBounds = true
- return nextButton
- }
- }
- extension HMSegmentedControl {
- func setupDefaultMTStyle() {
- backgroundColor = UIColor.clear
- type = .text
- selectionStyle = .textWidthStripe
- segmentWidthStyle = .dynamic
- selectionIndicatorLocation = .down
- selectionIndicatorHeight = 3
- selectionIndicatorColor = OJATextColor.colorMain
- selectedTitleTextAttributes = [NSAttributedString.Key.foregroundColor: OJATextColor.colorMain,
- NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 15)]
- titleTextAttributes = [NSAttributedString.Key.foregroundColor: OJATextColor.colorWhite,
- NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 15)]
- segmentEdgeInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 16) // 注意,segmentEdgeInset是针对每个segment的属性,而不是针对整个View的属性
- }
- func setupTabBarStyle() {
- backgroundColor = OJAStyle.backgroundColor
- type = .text
- selectionStyle = .textWidthStripe
- segmentWidthStyle = .fixed // yong fixed是为了在contentSize小于frame时能时segment均匀分布
- selectionIndicatorLocation = .down
- selectionIndicatorHeight = 3
- selectionIndicatorEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: -5, right: 0)
- selectionIndicatorColor = OJATextColor.colorWhite
- selectedTitleTextAttributes = OJAStyle.tabBarSelectedAttributeDict
- titleTextAttributes = OJAStyle.tabBarNormalAttributeDict
- segmentEdgeInset = UIEdgeInsets.zero // 注意,segmentEdgeInset是针对每个segment的属性,而不是针对整个View的属性
- }
- func setupPasterStyle() {
- backgroundColor = UIColor.clear
- type = .text
- selectionStyle = .fullWidthStripe
- segmentWidthStyle = .fixed // yong fixed是为了在contentSize小于frame时能时segment均匀分布
- selectionIndicatorLocation = .down
- selectionIndicatorHeight = 3
- selectionIndicatorEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: -5, right: 0)
- selectionIndicatorColor = OJATextColor.colorMain
- selectedTitleTextAttributes = [NSAttributedString.Key.foregroundColor: OJATextColor.colorMain,
- NSAttributedString.Key.font: OJAFont.font16]
- titleTextAttributes = [NSAttributedString.Key.foregroundColor: OJATextColor.color9,
- NSAttributedString.Key.font: OJAFont.font16]
- segmentEdgeInset = UIEdgeInsets.zero // 注意,segmentEdgeInset是针对每个segment的属性,而不是针对整个View的属性
- }
- }
- extension UILabel {
- func setupWithHomeCellDescAttributeDict(text: String?) {
- if let text = text {
- attributedText = NSAttributedString(string: text, attributes: WSSStyle.shared.homeCellDescAttributeDict)
- } else {
- attributedText = nil
- }
- }
- }
- extension UITextView {
- }
- extension UIColor {
- }
|