Skip to content

Commit

Permalink
4.2.0:兼容深色模式(可通过参数修改深色模式下的相关色值)
Browse files Browse the repository at this point in the history
  • Loading branch information
choiceyou committed Mar 20, 2021
1 parent f80049e commit d1b80e9
Show file tree
Hide file tree
Showing 33 changed files with 545 additions and 144 deletions.
2 changes: 1 addition & 1 deletion FWPopupView.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
#

s.name = "FWPopupView"
s.version = "4.1.6"
s.version = "4.2.0"
s.summary = "自定义弹窗"

# This description is used to generate tags and improve search results.
Expand Down
57 changes: 43 additions & 14 deletions FWPopupView/FWAlertView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ open class FWAlertView: FWPopupView {
private var detailLabel: UILabel?
private var inputTF: UITextField?
private var customView: UIView?
private var btnContrainerView: UIView!

private var commponenetCount: Int = 0

Expand Down Expand Up @@ -203,7 +204,7 @@ extension FWAlertView {
make.right.equalToSuperview().offset(-self.vProperty.letfRigthMargin)
})
self.titleLabel?.text = title
self.titleLabel?.textColor = self.vProperty.titleColor
self.titleLabel?.textColor = UIColor.fw_colorWithStyleColors(lightColor: self.vProperty.titleColor, darkColor: self.vProperty.dark_titleColor)
self.titleLabel?.textAlignment = .center
self.titleLabel?.font = (self.vProperty.titleFont != nil) ? self.vProperty.titleFont! : UIFont.systemFont(ofSize: self.vProperty.titleFontSize)
self.titleLabel?.numberOfLines = 5
Expand All @@ -223,7 +224,7 @@ extension FWAlertView {
make.height.lessThanOrEqualTo(self.superview!.frame.size.height*property.popupViewMaxHeightRate-100)
})
self.detailLabel?.text = detail
self.detailLabel?.textColor = property.detailColor
self.detailLabel?.textColor = UIColor.fw_colorWithStyleColors(lightColor: property.detailColor, darkColor: property.dark_detailColor)
self.detailLabel?.textAlignment = .center
self.detailLabel?.font = (property.detailFont != nil) ? property.detailFont! : UIFont.systemFont(ofSize: property.detailFontSize)
self.detailLabel?.numberOfLines = 0
Expand All @@ -243,11 +244,11 @@ extension FWAlertView {
make.height.equalTo(40)
})
self.inputTF?.attributedPlaceholder = NSAttributedString(string: inputPlaceholder!, attributes: [NSAttributedString.Key.foregroundColor : property.inputPlaceholderColor])
self.inputTF?.textColor = property.inputTextColor
self.inputTF?.textColor = UIColor.fw_colorWithStyleColors(lightColor: property.inputTextColor, darkColor: property.dark_inputTextColor)
self.inputTF?.textAlignment = .center
self.inputTF?.clearButtonMode = .whileEditing
self.inputTF?.leftViewMode = .always
self.inputTF?.layer.borderColor = self.vProperty.splitColor.cgColor
self.inputTF?.layer.borderColor = UIColor.fw_colorWithStyleColors(lightColor: self.vProperty.splitColor, darkColor: self.vProperty.dark_splitColor).cgColor
self.inputTF?.layer.borderWidth = self.vProperty.splitWidth
self.inputTF?.layer.cornerRadius = self.vProperty.cornerRadius
self.inputTF?.keyboardType = keyboardType
Expand All @@ -270,7 +271,7 @@ extension FWAlertView {
lastConstraintItem = self.customView!.snp.bottom
}

let btnContrainerView = UIView()
btnContrainerView = UIView()
self.addSubview(btnContrainerView)
btnContrainerView.backgroundColor = UIColor.clear
btnContrainerView.snp.makeConstraints { (make) in
Expand Down Expand Up @@ -322,16 +323,14 @@ extension FWAlertView {

// 按钮背景颜色
if popupItem.itemBackgroundColor != nil {
btn.backgroundColor = popupItem.itemBackgroundColor
btn.backgroundColor = UIColor.fw_colorWithStyleColors(lightColor: popupItem.itemBackgroundColor, darkColor: popupItem.dark_itemBackgroundColor)
} else {
btn.backgroundColor = self.backgroundColor
btn.backgroundColor = UIColor.fw_colorWithStyleColors(lightColor: self.vProperty.backgroundColor, darkColor: self.vProperty.dark_backgroundColor)
}
// 按钮文字颜色
if popupItem.itemTitleColor != nil {
btn.setTitleColor(popupItem.itemTitleColor, for: .normal)
} else {
btn.setTitleColor(popupItem.highlight ? self.vProperty.itemHighlightColor : self.vProperty.itemNormalColor, for: .normal)
}
let titleLightColor = (popupItem.itemTitleColor != nil) ? popupItem.itemTitleColor : ((popupItem.highlight == true) ? self.vProperty.itemHighlightColor : self.vProperty.itemNormalColor)
let titleDarkColor = (popupItem.dark_itemTitleColor != nil) ? popupItem.dark_itemTitleColor : ((popupItem.highlight == true) ? self.vProperty.dark_itemHighlightColor : self.vProperty.dark_itemNormalColor)
btn.setTitleColor(UIColor.fw_colorWithStyleColors(lightColor: titleLightColor, darkColor: titleDarkColor), for: .normal)

// 按钮文字大小
if popupItem.itemTitleFont != nil {
Expand All @@ -342,9 +341,9 @@ extension FWAlertView {

btn.setTitle(popupItem.title, for: .normal)
btn.layer.borderWidth = self.vProperty.splitWidth
btn.layer.borderColor = self.vProperty.splitColor.cgColor
btn.layer.borderColor = UIColor.fw_colorWithStyleColors(lightColor: self.vProperty.splitColor, darkColor: self.vProperty.dark_splitColor).cgColor
btn.setBackgroundImage(self.getImageWithColor(color: btn.backgroundColor!), for: .normal)
btn.setBackgroundImage(self.getImageWithColor(color: self.vProperty.itemPressedColor), for: .highlighted)
btn.setBackgroundImage(self.getImageWithColor(color: UIColor.fw_colorWithStyleColors(lightColor: self.vProperty.itemPressedColor, darkColor: self.vProperty.dark_itemPressedColor)), for: .highlighted)

tmpIndex += 1
}
Expand All @@ -356,6 +355,26 @@ extension FWAlertView {
make.bottom.equalTo(btnContrainerView.snp.bottom)
}
}

open override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)

if #available(iOS 13.0, *), FWPopupSWindow.sharedInstance.compatibleDarkStyle == true {
if self.traitCollection.hasDifferentColorAppearance(comparedTo: previousTraitCollection) {
for tmpView: UIView in self.btnContrainerView.subviews {
let btn: UIButton = tmpView as! UIButton
btn.setBackgroundImage(self.getImageWithColor(color: btn.backgroundColor!), for: .normal)
if self.traitCollection.userInterfaceStyle == .dark {
btn.layer.borderColor = self.vProperty.dark_splitColor.cgColor
btn.setBackgroundImage(self.getImageWithColor(color: self.vProperty.dark_itemPressedColor), for: .highlighted)
} else {
btn.layer.borderColor = self.vProperty.splitColor.cgColor
btn.setBackgroundImage(self.getImageWithColor(color: self.vProperty.itemPressedColor), for: .highlighted)
}
}
}
}
}
}

extension FWAlertView {
Expand Down Expand Up @@ -415,6 +434,16 @@ open class FWAlertViewProperty: FWPopupViewProperty {
@objc open var defaultTextConfirm = "确定"


// ===== 深色模式 =====

// 深色模式:描述文字颜色
@objc open var dark_detailColor: UIColor = kPV_RGBA(r: 149, g: 149, b: 149, a: 1)
// 深色模式:输入框提示文字颜色
@objc open var dark_inputPlaceholderColor: UIColor = UIColor.lightGray
// 深色模式:输入框文字颜色
@objc open var dark_inputTextColor: UIColor = kPV_RGBA(r: 149, g: 149, b: 149, a: 1)


public override func reSetParams() {
super.reSetParams()

Expand Down
24 changes: 11 additions & 13 deletions FWPopupView/FWCustomSheetView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class FWCustomSheetViewTableViewCell: UITableViewCell {
var imgView: UIImageView!
var titleLabel: UILabel!
var secondaryTitleLabel: UILabel!
var line: CALayer!
var line: UIView!

override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
Expand All @@ -30,8 +30,8 @@ class FWCustomSheetViewTableViewCell: UITableViewCell {
self.secondaryTitleLabel.numberOfLines = 1
self.addSubview(self.secondaryTitleLabel)

self.line = CALayer()
self.layer.addSublayer(self.line)
self.line = UIView()
self.addSubview(self.line)
}

required init?(coder aDecoder: NSCoder) {
Expand All @@ -42,7 +42,7 @@ class FWCustomSheetViewTableViewCell: UITableViewCell {
self.selectionStyle = property.selectionStyle

self.line.frame = CGRect(x: property.separatorInset.left, y: ceil(self.frame.height-property.splitWidth), width: self.frame.width-property.separatorInset.left-property.separatorInset.right, height: property.splitWidth)
self.line.backgroundColor = property.splitColor.cgColor
self.line.backgroundColor = UIColor.fw_colorWithStyleColors(lightColor: property.splitColor, darkColor: property.dark_splitColor)

var leftMargin = property.letfRigthMargin

Expand Down Expand Up @@ -167,13 +167,13 @@ extension FWCustomSheetView {
// 绘制头部视图
if headerTitle != nil {
self.headerView = UIView(frame: CGRect(x: 0, y: 0, width: selfSize.width, height: property.headerViewHeight))
self.headerView?.backgroundColor = self.vProperty.backgroundColor
self.headerView?.backgroundColor = UIColor.fw_colorWithStyleColors(lightColor: self.vProperty.backgroundColor, darkColor: self.vProperty.dark_backgroundColor)
self.addSubview(self.headerView!)

let line = CALayer()
let line = UIView()
line.frame = CGRect(x: 0, y: floor(property.headerViewHeight-property.splitWidth), width: selfSize.width, height: property.splitWidth)
line.backgroundColor = property.splitColor.cgColor
self.headerView!.layer.addSublayer(line)
line.backgroundColor = UIColor.fw_colorWithStyleColors(lightColor: self.vProperty.splitColor, darkColor: self.vProperty.dark_splitColor)
self.headerView!.addSubview(line)

let titleLabel = UILabel(frame: CGRect(x: property.letfRigthMargin, y: 0, width: selfSize.width-property.letfRigthMargin*3, height: property.headerViewHeight))
self.headerView!.addSubview(titleLabel)
Expand Down Expand Up @@ -204,7 +204,7 @@ extension FWCustomSheetView {

self.tableView.register(FWCustomSheetViewTableViewCell.self, forCellReuseIdentifier: "cellId")
self.tableView.separatorStyle = .none
self.tableView.backgroundColor = self.backgroundColor
self.tableView.backgroundColor = UIColor.fw_colorWithStyleColors(lightColor: self.vProperty.backgroundColor, darkColor: self.vProperty.dark_backgroundColor)
self.tableView.bounces = property.bounces

if property.popupViewMaxHeightRate > 0 && property.popupViewItemHeight * CGFloat(self.itemsCount()) > property.popupViewMaxHeightRate*self.superview!.frame.size.height {
Expand Down Expand Up @@ -239,7 +239,7 @@ extension FWCustomSheetView {
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cellId", for: indexPath) as! FWCustomSheetViewTableViewCell
cell.setupContent(title: (self.itemTitleArray != nil) ? self.itemTitleArray![indexPath.row] : nil, secondaryTitle: (self.itemSecondaryTitleArray != nil) ? self.itemSecondaryTitleArray![indexPath.row] : nil, image: (self.itemImageNameArray != nil) ? self.itemImageNameArray![indexPath.row] : nil, property: self.vProperty as! FWCustomSheetViewProperty)
cell.backgroundColor = self.vProperty.backgroundColor
cell.backgroundColor = UIColor.fw_colorWithStyleColors(lightColor: self.vProperty.backgroundColor, darkColor: self.vProperty.dark_backgroundColor)

let property = self.vProperty as! FWCustomSheetViewProperty
if property.lastNeedAccessoryView == true && indexPath.row == (self.itemsCount()-1) {
Expand Down Expand Up @@ -362,8 +362,6 @@ open class FWCustomSheetViewProperty: FWPopupViewProperty {
/// 选中风格
@objc public var selectionStyle: UITableViewCell.SelectionStyle = .none

/// 分割线颜色
@objc public var separatorColor: UIColor = kPV_RGBA(r: 231, g: 231, b: 231, a: 1)
/// 分割线偏移量
@objc public var separatorInset: UIEdgeInsets = UIEdgeInsets.zero

Expand All @@ -375,7 +373,7 @@ open class FWCustomSheetViewProperty: FWPopupViewProperty {

self.buttonFontSize = 15

self.titleTextAttributes = [NSAttributedString.Key.foregroundColor: self.itemNormalColor, NSAttributedString.Key.backgroundColor: UIColor.clear, NSAttributedString.Key.font: UIFont.systemFont(ofSize: self.buttonFontSize)]
self.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.fw_colorWithStyleColors(lightColor: self.itemNormalColor, darkColor: self.dark_itemNormalColor), NSAttributedString.Key.backgroundColor: UIColor.clear, NSAttributedString.Key.font: UIFont.systemFont(ofSize: self.buttonFontSize)]

let tmpColor = kPV_RGBA(r: 138, g: 146, b: 165, a: 1)
self.secondaryTitleTextAttributes = [NSAttributedString.Key.foregroundColor: tmpColor, NSAttributedString.Key.backgroundColor: UIColor.clear, NSAttributedString.Key.font: UIFont.systemFont(ofSize: 12)]
Expand Down
36 changes: 22 additions & 14 deletions FWPopupView/FWDateView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,31 +60,30 @@ extension FWDateView {
private func setupUI(confirmBlock: FWDateViewConfirmBlock? = nil, cancelBlock: FWPopupVoidBlock? = nil) {

let property = self.vProperty as! FWDateViewProperty
property.popupCustomAlignment = .bottomCenter
property.popupAnimationType = .position

self.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: property.datePickerHeight + property.btnHeight)

if #available(iOS 13.4, *) {
self.datePicker.preferredDatePickerStyle = .wheels
}
self.datePicker.setValue(property.pickerTextColor, forKey: "textColor")

self.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: property.datePickerHeight + property.btnHeight)
self.datePicker.frame = CGRect(x: 0, y: property.btnHeight, width: self.frame.width, height: property.datePickerHeight)
self.datePicker.backgroundColor = self.backgroundColor
self.datePicker.locale = Locale(identifier: "zh_Hans_CN")
self.datePicker.setValue(UIColor.fw_colorWithStyleColors(lightColor: property.pickerTextColor, darkColor: property.dark_pickerTextColor), forKey: "textColor")
self.addSubview(self.datePicker)

// 取消按钮
self.cancelBtn = self.setupBtn(frame: CGRect(x: 0, y: 0, width: property.btnWidth, height: property.btnHeight), title: property.cancelBtnTitle, tag: 0)
self.addSubview(self.cancelBtn!)

// 确定按钮
self.confirmBtn = self.setupBtn(frame: CGRect(x: self.frame.width - property.btnWidth, y: 0, width: property.btnWidth, height: property.btnHeight), title: property.confirmBtnTitle, tag: 1)
self.addSubview(self.confirmBtn!)

self.datePicker.frame = CGRect(x: 0, y: property.btnHeight, width: self.frame.width, height: property.datePickerHeight)
self.datePicker.backgroundColor = self.backgroundColor
// 默认
self.datePicker.locale = Locale(identifier: "zh_Hans_CN")
self.addSubview(self.datePicker)

self.confirmBlock = confirmBlock
self.cancelBlock = cancelBlock

property.popupCustomAlignment = .bottomCenter
property.popupAnimationType = .position
}

private func setupBtn(frame: CGRect, title: String, tag: Int) -> UIButton {
Expand All @@ -96,8 +95,8 @@ extension FWDateView {
btn.frame = frame
btn.tag = tag
btn.setTitle(title, for: .normal)
btn.setTitleColor(property.btnTitleColor, for: .normal)
btn.backgroundColor = self.backgroundColor
btn.setTitleColor(UIColor.fw_colorWithStyleColors(lightColor: property.btnTitleColor, darkColor: property.dark_btnTitleColor), for: .normal)
btn.backgroundColor = UIColor.clear
btn.titleLabel?.font = UIFont.systemFont(ofSize: property.btnTitleFont)
return btn
}
Expand Down Expand Up @@ -136,6 +135,15 @@ open class FWDateViewProperty : FWPopupViewProperty {
// 确定按钮名称
@objc public var confirmBtnTitle = "确定"


// ===== 深色模式 =====

// 时间选择器文字颜色
@objc public var dark_pickerTextColor: UIColor = kPV_RGBA(r: 213, g: 213, b: 213, a: 1)
// 按钮文字颜色
@objc public var dark_btnTitleColor: UIColor = kPV_RGBA(r: 213, g: 213, b: 213, a: 1)


public override func reSetParams() {
super.reSetParams()

Expand Down
Loading

0 comments on commit d1b80e9

Please sign in to comment.