Skip to content

Commit

Permalink
20230730.20
Browse files Browse the repository at this point in the history
  • Loading branch information
lianjun007 committed Jul 30, 2023
1 parent c93ddf2 commit 9cc7829
Show file tree
Hide file tree
Showing 15 changed files with 365 additions and 138 deletions.
8 changes: 6 additions & 2 deletions Fourm/Fourm.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -647,8 +647,10 @@
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
INFOPLIST_KEY_UIMainStoryboardFile = Main;
INFOPLIST_KEY_UIStatusBarStyle = "";
INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown";
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -675,8 +677,10 @@
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
INFOPLIST_KEY_UIMainStoryboardFile = Main;
INFOPLIST_KEY_UIStatusBarStyle = "";
INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown";
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
7 changes: 7 additions & 0 deletions Fourm/Fourm/DataFile/New Group/File
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
@backDeployed要求当前所在类型与修饰内容的访问权限不低于public。
@backDeployed适用于计算属性与方法。
#code Swift


import Foundation
import UIKit

Expand All @@ -32,6 +34,11 @@ func essayInterfaceBuild0(_ essayData: String, _ VC: UIViewController) {
}







##code
# [weak self]改变
Swift 5.3 之后 self 可以在闭包中有条件省略,Swift 5.8 之后类中的[weak self]也可以省略 self。
Expand Down
25 changes: 19 additions & 6 deletions Fourm/Fourm/FrameFile/BasicData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ struct Screen {
let window = windowScene?.windows.first
return window?.safeAreaInsets ?? UIEdgeInsets.zero
}
static func nativeHeight() -> CGFloat {
UIScreen.main.nativeBounds.height // 与设备屏幕宽度一样宽(物理)
}
static func width() -> CGFloat {
UIScreen.main.bounds.width // 与设备屏幕宽度一样宽
}
Expand All @@ -29,23 +32,33 @@ struct Screen {

/// 选择间距相关的方法,返回CGFloat
struct Spaced {
/// 屏幕边框与内容之间的间距
static func screen() -> CGFloat {
20 // 屏幕边框与内容之间的间距
20
}
/// 屏幕边框与内容之间的间距,会根据安全区域自动调整
static func screenAuto() -> CGFloat {
20 + Screen.safeAreaInsets().left // 屏幕边框与内容之间的间距,会根据安全区域自动调整
20 + Screen.safeAreaInsets().left
}
/// 各个相邻的控件之间的间距,也用做二级标题和模块之间的间距/
static func control() -> CGFloat {
10 // 各个相邻的控件之间的间距,也用做二级标题和模块之间的间距
10
}
/// 各个模块之间的间距/
static func module() -> CGFloat {
30 // 各个模块之间的间距
30
}
/// 各个设置之间的间距
static func setting() -> CGFloat {
25 // 各个设置之间的间距
25
}
/// 导航栏与第一个模块之间的间距
static func navigation() -> CGFloat {
18 // 导航栏与第一个模块之间的间距
18
}
/// 代码块的代码行间距
static func codeRow() -> CGFloat {
4
}
}

Expand Down
8 changes: 3 additions & 5 deletions Fourm/Fourm/FrameFile/ControlBuild.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,9 @@ extension Setting {
returnDictionary["view"] = settingControl

/// 控件上方的说明(`caption`)部分
let captionLabel = UILabel().fontAdaptive(caption, font: Font.tips())
let captionLabel = UILabel().fontAdaptive(caption, font: Font.tips(), width: Screen.basicWidth() - Spaced.screen() * 2)
if !caption.isEmpty {
captionLabel.frame.origin = CGPoint(x: Spaced.screen(), y: 0)
captionLabel.frame.size.width = Screen.basicWidth() - Spaced.screen() * 2
captionLabel.textColor = UIColor.black.withAlphaComponent(0.6)
settingControl.addSubview(captionLabel)
}
Expand Down Expand Up @@ -217,10 +216,9 @@ extension Setting {
}

/// 控件下方的提示(`tips`)部分
let tipsLabel = UILabel().fontAdaptive(tips, font: Font.tips())
let tipsLabel = UILabel().fontAdaptive(tips, font: Font.tips(), width: Screen.basicWidth() - Spaced.screen() * 2)
if !tips.isEmpty {
tipsLabel.frame.origin = CGPoint(x: Spaced.screen(), y: returnDictionary["\(control.count)"]!.frame.maxY + 6)
tipsLabel.frame.size.width = Screen.basicWidth() - Spaced.screen() * 2
tipsLabel.frame.origin = CGPoint(x: Spaced.screen(), y: returnDictionary["\(control.count)"]!.frame.maxY + captionLabel.frame.maxY + 6)
tipsLabel.textColor = UIColor.black.withAlphaComponent(0.6)
settingControl.addSubview(tipsLabel)
}
Expand Down
3 changes: 2 additions & 1 deletion Fourm/Fourm/FrameFile/ControlExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ extension UILabel {
///
/// - Parameter text: 内容
/// - Parameter font: 字体大小
func fontAdaptive(_ text: String, font: UIFont) -> UILabel {
func fontAdaptive(_ text: String, font: UIFont, width: CGFloat) -> UILabel {
let lable = UILabel()
lable.text = text
lable.font = font
lable.numberOfLines = 0
lable.frame.size.width = width
lable.sizeToFit()
return lable
}
Expand Down
103 changes: 80 additions & 23 deletions Fourm/Fourm/FrameFile/EssayControl copy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,37 @@ func title3ModuleBuild(_ string: String, _ view: UIView, originY: CGFloat) -> CG
func codeModuleBuild(_ stringArray: Array<String>, _ superView: UIView,_ pointY: CGFloat, language codeLanguage: String) -> CGFloat {
// 对空行进行处理
var codeStringArray = stringArray

// 根据是否去除前后空行的设置判断
if UserDefaults.SettingInfo.string(forKey: .essayCodeFristAndList)! == "true" {
// 去除前面的空行
for (index, element) in codeStringArray.enumerated() {
if !element.isEmpty {
codeStringArray.removeFirst(index)
break
}
}
// 去除后面的空行
var last = 0
var lastBool = false
for item in codeStringArray {
last += 1
if !item.isEmpty, lastBool {
lastBool = !lastBool
last = 0
} else if item.isEmpty, !lastBool {
lastBool = !lastBool
last = 0
}
}
if codeStringArray[codeStringArray.count - 1].isEmpty {
codeStringArray.removeLast(last + 1)
}
}

// 保留中间的空行
for (index, element) in codeStringArray.enumerated() {

if element.isEmpty {
codeStringArray[index] = " "
}
Expand All @@ -360,11 +390,10 @@ func codeModuleBuild(_ stringArray: Array<String>, _ superView: UIView,_ pointY:
// 处理代码行和行序号
var rowArray: Array<UILabel> = []
var codeRowMaxX = CGFloat(0) // 接收所有代码行的最大X轴坐标的属性
let rowSpacing = CGFloat(4) // 代码行之间的间距属性
for i in 0 ..< codeStringArray.count {
// 代码行部分
let codeRow = UILabel()
codeRow.frame.origin.y = i == 0 ? 10: rowArray[(i - 1) * 2].frame.maxY + rowSpacing
codeRow.frame.origin.y = i == 0 ? 10: rowArray[(i - 1) * 2].frame.maxY + Spaced.codeRow()
var newCodeString = NSMutableAttributedString(string: codeStringArray[i])
switch codeLanguage {
case "Swift": newCodeString = swiftCodeOptimize(attString: newCodeString)
Expand Down Expand Up @@ -426,8 +455,12 @@ func codeModuleBuild(_ stringArray: Array<String>, _ superView: UIView,_ pointY:
for (index, element) in rowArray.enumerated() {
let rowNumber = (index - 1) / 2 + 1 // 代码行的序号的具体数字
if index % 2 == 0 {
// 代码行部分
element.frame.origin.x = rowNumberBoxWidth + 10
// 代码行部分,判断是否有代码行前的序号以此来决定原点的X轴坐标值
if UserDefaults.SettingInfo.string(forKey: .essayCodeNumber) == "true" {
element.frame.origin.x = rowNumberBoxWidth + 10
} else {
element.frame.origin.x = 8
}
} else {
// 代码行的序号部分
switch rowNumberDigits {
Expand Down Expand Up @@ -462,7 +495,12 @@ func codeModuleBuild(_ stringArray: Array<String>, _ superView: UIView,_ pointY:

// 设置代码(滚动)块的样式
codeScrollBox.backgroundColor = UIColor.systemFill
codeScrollBox.contentSize.width = codeRowMaxX + rowNumberBoxWidth + 15
// 根据是否有代码块行前序号来判断代码块的contentSize
if UserDefaults.SettingInfo.string(forKey: .essayCodeNumber) == "true" {
codeScrollBox.contentSize.width = codeRowMaxX + rowNumberBoxWidth + 15
} else {
codeScrollBox.contentSize.width = codeRowMaxX + 16
}

// 代码行序号容器的样式
rowNumberBox.frame = CGRect(x: codeScrollBox.frame.origin.x, y: codeScrollBox.frame.origin.y, width: rowNumberBoxWidth + 5, height: codeScrollBox.frame.height)
Expand All @@ -480,8 +518,12 @@ func codeModuleBuild(_ stringArray: Array<String>, _ superView: UIView,_ pointY:
for (index, element) in rowArray.enumerated() {
let rowNumber = (index - 1) / 2 + 1 // 代码行的序号的具体数字
if index % 2 == 0 {
// 代码行部分
element.frame.origin.x = rowNumberBoxWidth + 5
// 代码行部分,判断是否有代码行前的序号以此来决定原点的X轴坐标值
if UserDefaults.SettingInfo.string(forKey: .essayCodeNumber) == "true" {
element.frame.origin.x = rowNumberBoxWidth + 5
} else {
element.frame.origin.x = 8
}
} else {
// 代码行的序号部分
element.frame.origin.x += 0
Expand Down Expand Up @@ -519,7 +561,12 @@ func codeModuleBuild(_ stringArray: Array<String>, _ superView: UIView,_ pointY:
codeScrollBox.backgroundColor = UIColor(red: 242/255.0, green: 242/255.0, blue: 247/255.0, alpha: 1.000)
codeScrollBox.layer.borderWidth = 1
codeScrollBox.layer.borderColor = UIColor(red: 138/255.0, green: 138/255.0, blue: 141/255.0, alpha: 1.000).cgColor
codeScrollBox.contentSize.width = codeRowMaxX + rowNumberBoxWidth + 10
// 根据是否有代码块行前序号来判断代码块的contentSize
if UserDefaults.SettingInfo.string(forKey: .essayCodeNumber) == "true" {
codeScrollBox.contentSize.width = codeRowMaxX + rowNumberBoxWidth + 10
} else {
codeScrollBox.contentSize.width = codeRowMaxX + 16
}

// 代码行序号容器的样式
rowNumberBox.frame = CGRect(x: codeScrollBox.frame.origin.x + 1, y: codeScrollBox.frame.origin.y + 1, width: rowNumberBoxWidth - 0.5, height: codeScrollBox.frame.height - 2)
Expand All @@ -533,23 +580,29 @@ func codeModuleBuild(_ stringArray: Array<String>, _ superView: UIView,_ pointY:
rowNumberBox.backgroundColor = UIColor.white.withAlphaComponent(0)
rowNumberBox.layer.masksToBounds = true

// 线条主题代码块中序号的分割竖线
let verticalLinePath = UIBezierPath()
let anchor = rowNumberBoxWidth + codeScrollBox.frame.origin.x
verticalLinePath.move(to: CGPoint(x: anchor, y: codeScrollBox.frame.origin.y))
verticalLinePath.addLine(to: CGPoint(x: anchor, y: codeScrollBox.frame.maxY))
let verticalLine = CAShapeLayer()
verticalLine.path = verticalLinePath.cgPath
verticalLine.lineWidth = 0.5
verticalLine.strokeColor = UIColor.black.withAlphaComponent(0.5).cgColor
superView.layer.addSublayer(verticalLine)
if UserDefaults.SettingInfo.string(forKey: .essayCodeNumber) == "true" {
// 线条主题代码块中序号的分割竖线,根据是否显示代码行设置来判断
let verticalLinePath = UIBezierPath()
let anchor = rowNumberBoxWidth + codeScrollBox.frame.origin.x
verticalLinePath.move(to: CGPoint(x: anchor, y: codeScrollBox.frame.origin.y))
verticalLinePath.addLine(to: CGPoint(x: anchor, y: codeScrollBox.frame.maxY))
let verticalLine = CAShapeLayer()
verticalLine.path = verticalLinePath.cgPath
verticalLine.lineWidth = 0.5
verticalLine.strokeColor = UIColor.black.withAlphaComponent(0.5).cgColor
superView.layer.addSublayer(verticalLine)
}
case "gorgeous":
// 设置代码行和序号的样式
for (index, element) in rowArray.enumerated() {
let rowNumber = (index - 1) / 2 + 1 // 代码行的序号的具体数字
if index % 2 == 0 {
// 代码行部分
element.frame.origin.x = rowNumberBoxWidth + 12
// 代码行部分,判断是否有代码行前的序号以此来决定原点的X轴坐标值
if UserDefaults.SettingInfo.string(forKey: .essayCodeNumber) == "true" {
element.frame.origin.x = rowNumberBoxWidth + 12
} else {
element.frame.origin.x = 8
}
} else {
// 代码行的序号部分
element.frame.origin.x += 7
Expand Down Expand Up @@ -585,16 +638,20 @@ func codeModuleBuild(_ stringArray: Array<String>, _ superView: UIView,_ pointY:

// 设置代码(滚动)块的样式
codeScrollBox.backgroundColor = UIColor(red: 222/255.0, green: 221/255.0, blue: 247/255.0, alpha: 1.000)
codeScrollBox.contentSize.width = codeRowMaxX + rowNumberBoxWidth + 17
// 根据是否有代码块行前序号来判断代码块的contentSize
if UserDefaults.SettingInfo.string(forKey: .essayCodeNumber) == "true" {
codeScrollBox.contentSize.width = codeRowMaxX + rowNumberBoxWidth + 17
} else {
codeScrollBox.contentSize.width = codeRowMaxX + 16
}

// 代码行序号容器的样式
rowNumberBox.frame = CGRect(x: 7 + codeScrollBox.frame.origin.x, y: 6 + codeScrollBox.frame.origin.y, width: rowNumberBoxWidth, height: codeScrollBox.frame.height - 12)
blurView.frame = CGRect(origin: CGPointZero, size: rowNumberBox.frame.size)
rowNumberBox.backgroundColor = UIColor.systemIndigo.withAlphaComponent(0.25)
rowNumberBox.layer.cornerRadius = 5
rowNumberBox.layer.masksToBounds = true
default:
break
default: break
}

return codeScrollBox.frame.maxY
Expand Down
6 changes: 6 additions & 0 deletions Fourm/Fourm/FrameFile/UserDefaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ extension UserDefaults {
case essayTheme
/// 阅读文章界面的代码块的序号行设置(`true、false`)
case essayCodeNumber
/// 阅读文章界面的代码块的前后空行是否去除功能(`true、false`)
case essayCodeFristAndList
}
}
}
Expand All @@ -38,4 +40,8 @@ func initializeUserDefaults() {
if UserDefaults.SettingInfo.string(forKey: .essayCodeNumber) == nil {
UserDefaults.SettingInfo.set(value: "true", forKey: .essayCodeNumber)
}
// 默认文章代码块前后空行是否去除为“true”,去除
if UserDefaults.SettingInfo.string(forKey: .essayCodeFristAndList) == nil {
UserDefaults.SettingInfo.set(value: "true", forKey: .essayCodeFristAndList)
}
}
2 changes: 1 addition & 1 deletion Fourm/Fourm/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ViewController: UITabBarController {
initializeUserDefaults()

let viewControllers = [
UINavigationController(rootViewController: LearningViewController().withTabBarItem(title: "推荐内容", image: UIImage(systemName: "books.vertical"), selectedImage: UIImage(systemName: "books.vertical.fill"))),
UINavigationController(rootViewController: LearningViewController().withTabBarItem(title: "推荐内容", image: UIImage(systemName: "book.pages"), selectedImage: UIImage(systemName: "book.pages.fill"))),
UINavigationController(rootViewController: DiscussViewController().withTabBarItem(title: "发现更多", image: UIImage(systemName: "safari"), selectedImage: UIImage(systemName: "safari.fill"))),
UINavigationController(rootViewController: CollectionViewController().withTabBarItem(title: "用户与收藏", image: UIImage(systemName: "star.square.on.square"), selectedImage: UIImage(systemName: "star.square.on.square.fill"))),
UINavigationController(rootViewController: SearchViewController().withTabBarItem(title: "搜索和设置", image: UIImage(systemName: "rectangle.and.hand.point.up.left"), selectedImage: UIImage(systemName: "rectangle.and.hand.point.up.left.fill")))
Expand Down
Loading

0 comments on commit 9cc7829

Please sign in to comment.